Date Assigned: Monday, March 10, or Tuesday, March 11, 2008.
Due Date: Monday, March 17, or Tuesday, March 18, 2008, before the beginning of your lab section.
Objective: The main objective of this assignment is to learn to design user-defined classes and ADTs.
Programming assignment: Because of the recent swings up and down in the stock market, you decide to watch the market more closely and write a Java program to compute the results of selling shares of stock.
Design a class named Stock that contains:
In your main method, write the statements to accomplish the following tasks:
1. Create a Stock object with appropriate data.
2. Prompt the user to enter an integer number representing number of stocks to sell (supply a range the integer should fall into).††
3. Determine the total profit if the number of shares entered by the user is sold at the current price, and display the results.† (Profit per share is computed by subtracting the purchase price from the current price.)†† Use the Stock objectís accessor methods to obtain the prices. Be sure to decrease the number of shares owned by the number sold, using the objectís mutator method.
4. Assume that the profit is too small, and experiment with the results by using the mutator method to increase the current stock price.
5. Determine the total profit for selling the same number of shares at the new current price, and display the results.
6. Use toString() to display all information for this stock, including percentage change in price from the previous day to the current price.†
For extra credit:† Include the code necessary to perform error checking for the number of shares the user wants to sell.† Do not accept a number larger than there are shares owned.† Place this code inside a loop so that the user may try again to enter a valid number of shares to sell.
Homework assignment: on a separate sheet of paper, solve Ex. 6 from p. 520 and Ex. 16 from p. 522.
Deliverables: as instructed by your TA.