Question: Note: Please provide source code for java only and the sample run (output) should be the same according to the question displayed below. Exercise#2: Design
Note: Please provide source code for java only and the sample run (output) should be the same according to the question displayed below.
Exercise#2: Design and implement class stock to represent a company's stock. The class defines the following attributes (variables) and methods 1. A class variable of type String named Symbol for the stock's symbol 2. A class variable of type string named Name for the stock's name 3. price A class variable of type double named previousclosingPrice to store the last closing 4. A class variable of tvpe double named currentprice to store the current price 5. A constructor method to create a stock with user-specified name and symbol 6. Method get Name () that returns the stock's name. 7. Method getsymbol that returns the stock's symbol 8. Method setclosin 9. Method setcurrentPrice() that sets the current price 10. Method getChangePercent () that returns the percentage changed from ce () that sets the previous closing price e to currentPrice. Using the formula * 100 eviousClosin 11.Method named toString ) printout a meaningful description of a stock object whern passing the object name to the print statement The statement PRINT vahooStock would print the string: Yahoo stock' s closing price is $234.54 Now design and implement a test program to create two stock objects: one for Google with symbol GOG and the second is for Microsoft with symbol MSF. Set their closing and current prices according to the information below. Next, test the class methods on each object to print the information in a similar manner to the one shown below Sample run: Google stock: Symbol: GOG Closing price 134.67 Current price 131.98 Change percent: - 25 Google stock closing price is $131.98 Microsoft stock: Symbol: MSF Closing price 156.52 Current price 161.22 Change percent: 3 Microsoft stock closing price is $161.22
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
