Question: In a file Stock.java, create a Stock class and make the class implement the Comparable interface. The member variables of the class should include the

In a file Stock.java, create a Stock class and make the class implement the Comparable interface. The member variables of the class should include the following: - A string data field named symbol for the stocks symbol. - A string data field named name for the stocks name. - A double data field named previousClosingPrice that stores the stock price for the previous day. - A double data field named currentPrice that stores the stock price for the current time. The constructor for the Stock class should allow the initialization of all the member variables above. The constructor for a Stock instance should also calculate a changePercent variable, which is basically the percentage the price changed from previousClosingPrice to currentPrice. The changePercent should be a private field of the class. For the purpose of this assignment, you are not required to provide setters and getters for symbol, name, previousClosingPrice, and currentPrice. You will also create a toString() method, which will print out the symbol, name, and changePercent field values of a stock. The overridden compareTo() method in the Stock class should compare the stocks based on their changePercent field values. Either in a separate file, or in the Stock.java, write code to create a list of 5 stocks: - One of the stocks should have the stock symbol ORCL, the name Oracle Corporation, the previous closing price of 34.5. and a new current price to 34.35; - The other 4 stocks will have your selection of stock data field values. Next, you will use the Arrays.sort method to sort the list of stocks, and print them out (using the toString() method) in ascending order. Examine the sample output below, and include the necessary texts for outputs; you do not need to replicate the stock values other than the indicated ORCL stock values above. Stocks in order: CSCO Cisco Systems -- change percent -15.73 HPQ Hewlett Packard -- change percent -4.31 ORCL Oracle Corporation -- change percent -0.43 IBM Int'l Business Machines -- change percent 2.86 SUNW Sun Microsystems -- change percent 3.54

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!