Project #54072 - program

CS-202 Lab 3

Due Date: Check CSNS

For this lab you will create a StockPrice class that represents information about the price of a stock during one day, and then create a StockMarket class that manages StockPrices. One of the key functions of StockMarket is to read and write data using a text file.

Part I - StockPrice class

Create a Java Class called StockPrice . Each object represents information about the price of a stock on a particular date. The data includes information on the date, the stock symbol, and the price of the stock at market opening and closing.

StockPrice should have the following:

  • privateData Fields:
    • int month : stores the month (01 for January through 12 for December) of the date of the current StockPrice data.
    • int day : stores the day of the month (01 through 31) for the date
    • int year : stores the year of the stock as a four-digit value (for example, 2010)
    • String name : stores the three or four-letter symbol for the name of the stock (for example, GOOG)
    • double open : stores the opening price of the stock for the day
    • double close : stores the closing price of the stock for the day
  • publicconstructors:
    • You should create a public constructor which has the following header:
      public StockPrice(String name, String date, double open, double close)
      NOTE: The date should be given to the constructor as a string in the format "Month/Day/Year", but in the constructor you will have to parse this string so that the month, day, and year are stored in their own variables.
  • publicMethods:
    • Your StockPrice class should accessor (getter) and mutator (setter) methods for all your fields. Eclipse can generate these automatically, but write a few of them yourself.
    • toString() : you should override the toString() method to format your object output to look similar to the following. NOTE: The values of each object will be different, this is simply an example illustrating how it should be formatted for output.
      Stock Name: AAPL
      Date: 11/24/2009
      Opening: 127.02
      Closing: 126.68
      Highest: 128.02
      Lowest: 124.23

Part II - StockMarket

Create a StockMarket class that keeps track of the StockPrice objects. It should contain a menu that allows the user to choose to quit or to do any of the following tasks, which must all be implemented in separate methods. After doing any of these tasks, the program should return to the menu, so that the user can continue working on any series of tasks until he/she chooses to quit.

  • Parse the input file and use the data to populate the variables for StockPrices. One line of the input file corresponds to one StockPrice object, so you should create as many objects as necessary to hold all of the data from the file. In each line of the input file, the first value is the date in the format mm/dd/yyyy; this needs to be parsed further into the month, day, and year, which are separate variables in StockPrice. The second value is the stock symbol, which represents the name of the stock; it is usually an abbreviation of the name of the company issuing the stock. The next value is the opening price of the stock for that day, the price when the market opened in the morning. The final value is the price of the last sale before the market closed. Although you can easily find out how many lines there are in the particular input file, you must write your program so that it will work with files of any size, and you will write methods to add and delete StockPrices. Use an ArrayList, not an array, to hold the StockPrices.
  • Create a new StockPrice object using data taken from input (command line or JOptionPane).
  • Choose a StockPrice from the array list and delete it.
  • Show the current list of stock prices, including their dates and all other fields. Write this method so that the program does not crash if there are no stocks in the array list yet.
  • Take the ArrayList of StockPrice objects and write the data to a file. The output should be formatted the same way as the given input file. The date should be put back together, and each piece of data in the object should be separated by commas. given file name as a string argument and parse the file. Be sure to save the file as a .csv file.

You may want to write a driver class to test out StockPrice's methods to cut down on your use of the user input methods while you are testing your work.


Subject Computer
Due By (Pacific Time) 01/28/2015 12:00 am
Report DMCA

Chat Now!

out of 1971 reviews

Chat Now!

out of 766 reviews

Chat Now!

out of 1164 reviews

Chat Now!

out of 721 reviews

Chat Now!

out of 1600 reviews

Chat Now!

out of 770 reviews

Chat Now!

out of 766 reviews

Chat Now!

out of 680 reviews
All Rights Reserved. Copyright by - Copyright Policy