Advertisement
akosiraff

Stock JAVA

Nov 18th, 2013
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1.  
  2. Download: http://solutionzip.com/downloads/stock-java/
  3. 1. Define a class named Stock that contains the following variables and methods (note that none of the methods for this step should be static):
  4. a. A String variable named symbol for the stock symbol.
  5. b. A String variable named name for the stock’s name.
  6. c. A double variable named previousClosingPrice that stores the previous day’s stock price.
  7. d. A double variable named currentPrice that stores the stock price for the current time.
  8. e. A constructor that creates a new Stock. The constructor takes the stock’s symbol, name, and previous price as its arguments.
  9. f. A method named setPrice() that updates the value of the currentPrice variable with its argument. This method does not return any value.
  10. g. A method named getChangePercent() that returns the percentage difference between previousClosingPrice and currentPrice. In other words:
  11. percentage difference = 100 * (currentPrice – previousClosingPrice) / previousClosingPrice
  12. This method returns a double value, and does not take any arguments.
  13. h. A method named toString() that does not take any arguments, but returns a String value. This String should contain the stock symbol, its name, its current price, and the change percentage. For example, calling toString() on a Stock object might return a String like the following:
  14. MSTK My Stock, Ltd. 34.56 22.8
  15. 2. Add a main() method (or create a second class with a main() method). In your main() method:
  16. a. Create three Stock objects with the following information:
  17. i. Stock symbol “JAVA”, name “Sun Microsystems, Inc.”, and previous closing price of 4.5
  18. ii. Stock symbol “GOOG”, name “Google Inc.”, and previous closing price of 1007.95
  19. iii. Stock symbol “AAPL”, name “Apple Inc.”, and previous closing price of 512.49
  20. b. Set
  21. i. JAVA — 4.35
  22. the current price of each stock as follows:
  23. ii. GOOG — 1012.45
  24. iii. AAPL — 509.12
  25. c. Finally, print each stock’s information by passing each Stock variable to System.out.println(). This will automatically call the stock’s toString() method.
  26.  
  27. Download: http://solutionzip.com/downloads/stock-java/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement