Free Essay

Stocks Java

In:

Submitted By sisterofbattle
Words 691
Pages 3
Lab 4-1 Create a Java Program to Stock Class package myjavaproject2;

public class Lab4_1 {

public static void main(String[] args) { // TODO Auto-generated method stub Stock stock = new Stock("ESI", "ITT Technical Institute Inc."); stock.setPreviousClosingPrice(60.0);

// Set current price stock.setCurrentPrice(65.0);

// Display stock info System.out.println("Symbol: " + stock.getSymbol); System.out.println("Name: " + stock.getName); System.out.println("Previous Closing Price: " + stock.getPreviousClosingPrice()); System.out.println("Current Price: " + stock.getCurrentPrice()); System.out.println("Price Change: " + stock.getChangePercent() * 1); } }

class Stock { String getSymbol; String getName; double previousClosingPrice; double currentPrice;

public Stock() { }

public Stock(String Symbol, String Name) { getSymbol = Symbol; getName = Name; } public String getSymbol(){ return getSymbol; } public String name(){ return getName; }

public double getChangePercent() { return (currentPrice - previousClosingPrice) / previousClosingPrice; } public double getPreviousClosingPrice() { return previousClosingPrice; } public double getCurrentPrice() { return currentPrice; } public void setCurrentPrice(double price) { currentPrice = price; } public void setPreviousClosingPrice(double price) { previousClosingPrice = price; } public void setgetSymbol(String Symbol) { getSymbol = Symbol; } public void setname(String name) { getName = name; }

}

Lab 4-2: Create a Java Program to Display a Calendar package myjavaproject2; import javax.swing.JOptionPane; public class Lab4_2 { public static String output =""; public static void main(String[] args) { // TODO Auto-generated method stub // Prompt the user to enter year String yearString = JOptionPane.showInputDialog(null, "Enter full year (i.e. 2001):", "Enter Year", JOptionPane.QUESTION_MESSAGE);

// Convert string into integer int year = Integer.parseInt(yearString);

// Prompt the user to enter month String monthString = JOptionPane.showInputDialog(null, "Enter month in number between 1 and 12:", "Enter Month", JOptionPane.QUESTION_MESSAGE);

// Convert string into integer int month = Integer.parseInt(monthString); // Print calendar for the month of the year printMonth(year, month); JOptionPane.showMessageDialog(null, output); } /** Print the calendar for a month in a year */ static void printMonth(int year, int month) { // Get start day of the week for the first date in the month int startDay = getStartDay(year, month);

// Get number of days in the month int numOfDaysInMonth = getNumOfDaysInMonth(year, month);

// Print headings printMonthTitle(year, month);

// Print body printMonthBody(startDay, numOfDaysInMonth); }

/** Get the start day of the first day in a month */ static int getStartDay(int year, int month) { // Get total number of days since 1/1/1800 int startDay1800 = 3; long totalNumOfDays = getTotalNumOfDays(year, month);

// Return the start day return (int)((totalNumOfDays + startDay1800) % 7); }

/** Get the total number of days since Jan 1, 1800 */ static long getTotalNumOfDays(int year, int month) { long total = 0;

// Get the total days from 1800 to year -1 for (int i = 1800; i < year; i++) if (isLeapYear(i)) total = total + 366; else total = total + 365;

// Add days from Jan to the month prior to the calendar month for (int i = 1; i < month; i++) total = total + getNumOfDaysInMonth(year, i);

return total; }

/** Get the number of days in a month */ static int getNumOfDaysInMonth(int year, int month) { if (month == 1 || month==3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) return 31;

if (month == 4 || month == 6 || month == 9 || month == 11) return 30;

if (month == 2) if (isLeapYear(year)) return 29; else return 28;

return 0; // If month is incorrect. }

/** Determine if it is a leap year */ static boolean isLeapYear(int year) { if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))) return true;

return false; }

/** Print month body */ static void printMonthBody(int startDay, int numOfDaysInMonth) { // Pad space before the first day of the month int i = 0; for (i = 0; i < startDay; i++) output +=" ";

for (i = 1; i <= numOfDaysInMonth; i++) { if (i < 10) output +=" " + i; else output +=" " + i;

if ((i + startDay) % 7 == 0) output += "\n"; }

output += "\n"; }

/** Print the month title, i.e. May, 1999 */ static void printMonthTitle(int year, int month) { output += " " + getMonthName(month) + ", " + year + "\n"; output += "-------------------------------------------\n"; output += " Sun Mon Tue Wed Thu Fri Sat\n"; }

/** Get the English name for the month */ static String getMonthName(int month) { String monthName = null; switch (month) { case 1: monthName = "January"; break; case 2: monthName = "February"; break; case 3: monthName = "March"; break; case 4: monthName = "April"; break; case 5: monthName = "May"; break; case 6: monthName = "June"; break; case 7: monthName = "July"; break; case 8: monthName = "August"; break; case 9: monthName = "September"; break; case 10: monthName = "October"; break; case 11: monthName = "November"; break; case 12: monthName = "December"; }

return monthName; } }

Similar Documents

Free Essay

Master

...incorporate design philosophy as well as user friendly interface into the system, meanwhile to have powerful functions that manifest all the users’ requirements and needs. One concern is how to reflect inventory level as quick as possible, since the sales of liquor occupy a large proportion compared with the daily transactions of the entire restaurant. Therefore, liquor’s inventory level changes constantly. In order to monitor these changes over periods, the Automated Inventory Management System can efficiently and accurately accomplish it while provides other services to the restaurant such as recording daily liquor sales. To users, the system can provide instant information about all inventory items. Therefore users who manage stock level can immediately solve any shortage problems, since the system provides easy-to-use interface for users to see inventory levels. By recording daily sales, the system updates inventory constantly with the...

Words: 2794 - Pages: 12

Premium Essay

Inventory

...General Services Office Inventory System Chapter 1 THE PROBLEM AND ITS BACKGROUND Introduction Computer systems and applications are basic tools used for companies and even small businesses nowadays. In order to make the tasks easier and avoid time consuming, computer technologies are now a big help. It provides tools for the employees in every office for easy tracks of daily activities related to their jobs. The computer systems and applications we create plays a vital role to make the daily works made easier, less time and efforts, more productive and accurate especially in an establishments like school offices. Computerization is now the basic necessity for every establishment, yet there are also still using manual methods which make them outdated. The General Services Office (GSO) of Divine Word College of San Jose is one of the offices which used manual methods for keeping records and transactions which make them consume lot of time and effort to find and manage all the information they needed. The data and transactions may not 100% reliable because it is handwritten and or because of human error lack of detection. The General Services Office Inventory and Scheduling system is designed to give accurate data about the first in and first out items within the office and provide accurate information on day to day schedules and reservations of specific rooms to avoid errors and conflicts to a certain schedules. The personnel in charge for the system have a convenient...

Words: 1865 - Pages: 8

Free Essay

Thesis

...CONCLUSION AND RECOMMENDATION Summary Because Lots A Pizza Bayan, Dasmariñas City is having difficulty using the manual process of their inventory and sales the researchers used this opportunity to develop a LAN-based inventory and sales management system for them. It minimized the manual task and maximized the employees’ time on doing their work because it lessens the time on generating sales and inventory summaries and reports. The researchers used NetBeans 7.1.1 Java SE as programming language and MySQL 5.1 command line client as database server. They started the development of the system on November 2011 and finished on January 2013. Conclusion The new system minimizes the time needed in managing and monitoring of inventory and sales of the business and it lessens the time and difficulty in generating reports. Based on the evaluation , the system got a mean 4.40 that proved to be very satisfactory and the system helps the employees to manage inventories and notify them that if there are critical stocks in the inventory. The system minimizes the effort in monitoring of sales performance and checking of inventory status. Delivery transactions are being organized and queued according to their date of transaction with the aid of the system. Advance delivery orders are accommodated by the system in proper queue and the system notify the user if there are advance orders. The system provides reports for sales performance. The system proved to be very satisfactory to the user...

Words: 597 - Pages: 3

Free Essay

Sun Micro Systems Case Study

...SPARCstation 10 system, the world’s first multiprocessing desktop computer in 1992. That same year they shipped more multiprocessing UNIX servers than any other vendor in their entire history of operation. Other major products contributed by Sun include the Solaris Operating System, Sparc Microprocessor, instant networking with Jini technology; which enables all kinds of devices to connect to the network—plug and play, and of course the famous Java technology. SUN Microsystems enjoyed 1.3 billion in revenues 1996 with server sales and topping out at 16 billion in quarterly sales in 1998 with the technology frenzied internet boom (Afuah & Tucci, 2003, p. 393). Java Technology Revolution: Java is by far the most widely used language in the world and is implemented in such places as web development, cell phones, gas pumps, and computers. Sun’s main involvements with Java are currently with their J2EE servers, workstations, Java development tools, standards, and the Solaris operating system (Sun Microsystems, 2006). Developed in early-1990, the Java platform was designed with the goal of allowing programs to...

Words: 3479 - Pages: 14

Free Essay

Java Tutorials

...The Java™ Web Services Tutorial For Java Web Services Developer’s Pack, v2.0 February 17, 2006 Copyright © 2006 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, U.S.A. All rights reserved.U.S. Government Rights - Commercial software. Government users are subject to the Sun Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its supplements. This distribution may include materials developed by third parties. Sun, Sun Microsystems, the Sun logo, Java, J2EE, JavaServer Pages, Enterprise JavaBeans, Java Naming and Directory Interface, EJB, JSP, J2EE, J2SE and the Java Coffee Cup logo are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. Unless otherwise licensed, software code in all technical materials herein (including articles, FAQs, samples) is provided under this License. Products covered by and information contained in this service manual are controlled by U.S. Export Control laws and may be subject to the export or import laws in other countries. Nuclear, missile, chemical biological weapons or nuclear maritime end uses or end users, whether direct or indirect, are strictly prohibited. Export or reexport to countries subject to U.S. embargo or to entities identified on U.S. export exclusion lists, including, but not limited to, the denied persons and specially designated nationals lists is strictly prohibited. DOCUMENTATION IS PROVIDED "AS IS" AND ALL EXPRESS OR...

Words: 55069 - Pages: 221

Premium Essay

C++ Programming

...C++ PROGRAMMING: FROM PROBLEM ANALYSIS TO PROGRAM DESIGN FIFTH EDITION D.S. MALIK Australia  Brazil  Japan  Korea  Mexico  Singapore  Spain  United Kingdom  United States C++ Programming: From Problem Analysis to Program Design, Fifth Edition D.S. Malik Executive Editor: Marie Lee Acquisitions Editor: Amy Jollymore Senior Product Manager: Alyssa Pratt Editorial Assistant: Zina Kresin Content Project Manager: Matthew Hutchinson Art Director: Faith Brosnan Print Buyer: Julio Esperas Cover Designer: Roycroft Design/ www.roycroftdesign.com Cover Photo: ª Guntmar Fritz/Masterfile Proofreader: Green Pen QA Indexer: Elizabeth Cunningham Compositor: Integra ª 2011 Course Technology, Cengage Learning ALL RIGHTS RESERVED. No part of this work covered by the copyright herein may be reproduced, transmitted, stored or used in any form or by any means graphic, electronic, or mechanical, including but not limited to photocopying, recording, scanning, digitizing, taping, Web distribution, information networks, or information storage and retrieval systems, except as permitted under Section 107 or 108 of the 1976 United States Copyright Act, without the prior written permission of the publisher. For product information and technology assistance, contact us at Cengage Learning Customer & Sales Support, 1-800-354-9706 For permission to use material from this text or product, submit all requests online at www.cengage.com/permissions Further permissions questions can be...

Words: 11776 - Pages: 48

Premium Essay

Prog Research Paper Unit 1

...1970’s Dartmouth Basic- was created by John Kemeny and Thomas Kurtz on May 1, 1964. Basic stands for Beginners All-purpose Symbolic Instruction Code . The aims of the BASIC system were: to develop a system and language that was friendly, easy to learn and use, to introduce computing as an adjunct to other courses, to operate an open access policy (i-programmer.info, 2010). Pascal- was created by Niklaus Wirth in 1972. He wanted a language suitable for teaching but for teaching computer science. It is best described as a simplified version of Algol. It was simplified both to make it easier to learn and to make it easier to compile (i-programmer.info, 2010). C- Was created by Ken Thompson iin the form of B and tweaked by Dennis Ritchie and renamed C in the 1970’s. It was the original code Unix was written in. Its function was for ease of use (i-programmer.info, 2010). Forth- was created by Charles H Moore in the 1970’s. The motivation behind this language was for both interactive execution of commands and the ability to compile sequences of commands for later execution (i-programmer.info, 2010). PLEX (Programming Language for EXchanges)- was created by Goran Hemdahl at Ericsson in the 1970’s. It is a special-purpose, pseudo-parallel and event-driven real-time programming language dedicated for AXE telephone exchanges, It is a propriatary language (i-programmer.info, 2010). 1980’s Atari ST BASIC – Atari commissioned MetaComCo to write a version of BASIC that...

Words: 1761 - Pages: 8

Premium Essay

Code Resusability

...Reusability of Code PRG/211 Reusability of Code When a developer is deciding to write code or a full out program, he/she must take into account the method of the code. There are many types of programming languages, but there are essentially two types of programming: procedural and object oriented (OPP). Both have their place in programming but you can also find procedural in OOP as well. But first we need to see what are the differences and similarities between the two. Structured programming consists of a level of such straightforwardness is reached that the execution is obvious to the programmer. Object-oriented programming consists of assemblage code with the data on which it operates so that this "object" can function separately of the rest of the software system. Structured programming and object-oriented programming are not exclusive from each other. You can structure the code in an object, and you can use objects to implement the modules of code in a structured program. Task vs. Data Structured programming is based around data structures and subroutines. The subroutines are where stuff actually "happens", and the data structures are simply containers for the information needed by those subroutines. Object oriented programming, on the other hand, shifts your primary focus to the data itself. Instead of asking "what do I want to do and what will I need to know to do it", you ask "what kind of things do I want to have and what can those things do for...

Words: 335 - Pages: 2

Free Essay

.Net and Java Technology Comparison

....NET & Java Comparsion Activity Zeferino Reyes CSS - 422 December 12, 2011 Nasser Alaeddine .NET & Java Comparison Activity In this written document will focus on the advantages and disadvantages or the use of .NET technology in use compared to the use of JAVA Technology as Software Architecture, (University of Phoenix, 2010, 2009, 2008, 2007, 2006, 2005). .NET technology is the means to “connect” meaning connecting software, people, structures, things like printers, networks, computers, anything one can think of, (Getdotnnu.com, 2004-06). JAVA Technology is known to be adaptable where it can connect computers to networks, mobile phones to the internet, and game consoles such as the new Playstation 3, Xbox 360, and Nintendo Wii to the internet to access web browsing, built in plug in like Netflix to watch movies, and to other consoles for online gaming like the popular shooter Call of Duty. Advantages of .NET technologies are that it has the ability to grab internet servers that web services and tools such as internet apps or anything that can produce these services. One profitable feature of .NET is its ASP.net technologies that allows for the making of additional websites and net services that exist on the .NET infrastructure, (Getdotnu.com, 2004-06). Another powerful advantage of .NET technology is the ASP feature is that it creates construction sites, services and applications and does not require as much coding as the older coding in the beginning...

Words: 705 - Pages: 3

Free Essay

Web 238 Team Assignment

...information to share. The basic Web site is built with HTML, and then creatively enhanced with CSS. To create a visually expressive Web site that can attract thousands of visitors each day you need to use more than HTML and decide what the site contains. There are different languages that can be used to add a sense of style to your site, some of the possible devices are JavaScript, Java, DOM, and AJAX. In the following paper our team will discuss a few examples of how each can be used in Web development. Comparison of Java and JavaScript Java and JavaScript are both object-oriented languages (Burns, 2012). Knowing how to use one language often becomes confusing when attempting to learn the other. Some of the differences between the two are that Java applets can create stand-alone applications that work across platforms running as standalone programs. However, JavaScript cannot create these stand-alone applications and reside on an Internet browser. A programmer must compile Java code before the program can run. This requires an outside program just to compile the code. A compiler turns Java code into machine language code before a browser can interpret it. Any changes the programmer makes to the code will require him to recompile the program and this can be a real tedious act to commit over and over. A web designer can write JavaScript functions directly in a text editor, saving the file and upload it to the server for immediate execution or using an editor like Adobe...

Words: 2442 - Pages: 10

Premium Essay

Goal Evaluation Matrix

...Communication Styles Worksheet You spent the past few days exploring the resources available to students at University of Phoenix, and you want to share what you learned with a friend who is interested in enrolling. Write a 150- to 200-word e-mail to your friend summarizing the resources available to students. Hey Dina, So as you know I have been in school online and I am really enjoying it. I really want to encourage you to do it as well. It is so easy and completely fools proof! Oh my gosh seriously you need to try it too. Right from my home page I can access the library where I can get research done or check my papers for potential plagiarism or errors. I can access different tutorials and labs ranging from ways to avoid plagiarism to java programming. I can even get assistance in math. There is a media library as well as so many other resources like a normal library. I don’t have to worry about getting in the car and going to the school to fight for a computer in their library. It is all just right here. The best part is I can do this online at home. Or when I am at work on break I can get on it from my phone. Easy stuff! Anyhow just let me know what you think. I would love to hear you are also going back to school as well. You asked your facilitator to review your e-mail draft. She liked what you wrote and asked you to write a summary to post in the class forum for the other students to read. Write a 150- to 200-word summary for your class of the resources available...

Words: 485 - Pages: 2

Premium Essay

Java

...that has made his work popular with programmers for many years. Michael Schidlowsky and Sedgewick have developed concise new Java implementations that both express the methods in a natural and direct manner and also can be used in real applications. Algorithms in Java, Third Edition, Part 5: Graph Algorithms is the second book in Sedgewick's thoroughly revised and rewritten series. The first book, Parts 1-4, addresses fundamental algorithms, data structures, sorting, and searching. A forthcoming third book will focus on strings, geometry, and a range of advanced algorithms. Each book's expanded coverage features new algorithms and implementations, enhanced descriptions and diagrams, and a wealth of new exercises for polishing skills. The natural match between Java classes and abstract data type (ADT) implementations makes the code more broadly useful and relevant for the modern object-oriented programming environment. The Web site for this book (www.cs.princeton.edu/~rs/) provides additional source code for programmers along with a variety of academic support materials for educators. Coverage includes: A complete overview of graph properties and types Diagraphs and DAGs Minimum spanning trees Shortest paths Network flows Diagrams, sample Java code, and detailed algorithm descriptions A landmark revision, Algorithms in Java, Third Edition, Part 5 provides a complete tool set for programmers to implement, debug, and use graph algorithms...

Words: 281 - Pages: 2

Premium Essay

Developer

...Programming--Malone Basics of Java Programming (A Work In Progress) What Constitutes a Java Program? A Java program consists of one or more source files. Each source file is called .java, where is the name of the class contained in that source file and .java is the extension that identifies the file as a Java source code file. In general, each source file contains one class. The name of the class must match the name of the file (without the extension) exactly. To execute a Java program, you first need to compile the source code into byte code. Byte code files have the name .class. If you’re working from the shell, this is done using the javac command (where “c” is for compiler). Usually we will be compiling using the Xcode IDE. Once compiled, the program is executed using the Java interpreter (a.k.a. the Java Virtual Machine or JVM). From the shell, the JVM is invoked with the “java” command. Again we will usually be doing this with the Build and Go or Debug options of the Xcode IDE. A Java program must have a routine called main(), which is the starting point for program execution. main() will always look something like this: public static void main (String args[]) { // insert code here... System.out.println("Hello World!"); } Source Code Formatting Keep in mind the following when writing Java source code: Java is case sensitive (“foo”, “Foo”, and “fOO” are all considered to be different in Java). • Every line of code in Java must end in a semi-colon (“;”). • Java doesn’t care about white...

Words: 968 - Pages: 4

Free Essay

C++ Template

...INTRODUCTION TO TEMPLATES *Mr.A.N.Shah, **Mr. N. N. Shah *P.G. Student,Computer Department, C.U.Shah College of Engineering & Technology, Wadhwan City **Lecturer (E.C.), R.K. University school of Engineering, Rajkot. ABSTRACT Templates allow us to define generic class and function. So it supports generic programming. Generic programming is an approach where generic types are used as parameters in algorithms so that they work for a variety of suitable data types and data structures. A template can be used to create a family of classes or functions. For example, it can be used with class like student etc and it also can be used for function mul() etc. A template is also known as a kind of macro. Whenever template is created for any class it required substituted data types. Since template is define with a parameter for classes or functions so it is sometime called as parameterized classes or functions. The main aim of this thesis is to show various ways to use template either with function or class. INTRODUCTION Template is one which supports generic class and function. So it supports generic programming. Generic programming is an approach where generic types are used as parameters in algorithms so it supports variety of suitable data types and data structures. CLASS TEMPLATE Following is syntax of class template. template class class-name { //………… // class members specification //...

Words: 265 - Pages: 2

Premium Essay

Is Technology Moving Faster Than Ethics ??

...defined inside and outside of a method. c) True d) False 4. Types defined in the programming language itself are called _____________ types. a) b) c) d) Class Primitive Library All of the above 5. Circle all that apply. Which of the following lines is not a Java comment? a) b) c) d) e) /** comments */ // comments -- comments /* Comments */ ** comments ** 1 6. For each software development concept below indicate whether it applies at design time, runtime, or both. You should circle one letter on each line. The first line is an example. Compiling source files Logic errors Syntax errors a) Design time a) Design time a) Design time b) Runtime b) Runtime b) Runtime c) Both c) Both c) Both 7. Which Java operator is used to access variables and methods belonging to an object? a) b) c) d) e) The [] operator The -> (arrow) operator The _ (underscore) operator The . (dot) operator None of the above 8. Suppose you’ve written a Java class called Quadratic. To create an object variable using that class you should write the following: a) b) c) d) Quadratic equation = Quadratic(); Quadratic() = new Quadratic; Quadratic equation = new Quadratic(); Quadratic equation = new Equation(); 2 B) Fill in the Blanks 9. The Java primitive type ____________ uses 16 bits to store positive and negative whole number values. 10. Examine the following code fragment: 1. int value = 12; 2. value = value * (3/2); 3. value = value % 2; 4. value = value - 11; 5. value = value / 3; 6. System...

Words: 604 - Pages: 3