Question: In java Part 1: Design a Stock class that contains information for: stock symbol, company name, and stock price. The Stock class will provide the
In java
Part 1: Design a Stock class that contains information for: stock symbol, company name, and stock price. The Stock class will provide the ability to initialize the stocks values. If the values are not provided, default values will be used. The class will provide the capability to compute the cost of purchasing the stock, given the stocks price per share, and a number of shares to be purchased (number of shares will be provided by the user). Users of the class can also reset the value for the stocks price, and view the stocks information.
Class Design Complete the design of the class below. Specify the accessibility (public vs. private) for the attributes and methods, as well as the data types for the attributes, and return types and parameters for the methods.
Attribute list:
Method list:
Stock.java publicclass Stock
{
}//end of Stock class
Part 2: Complete the below RunStock class, which has a main method. Here, we will create objects of the Stock class and demonstrate how to initialize its attributes and compute the cost of purchasing a stock. Create 2 objects of the Stock class one will have the attributes preset in the main method, and the other will have the attributes entered by the user). For each stock, the program should display all the stock information, ask the user how many shares he/she will like to purchase, and display the cost of purchasing the stock.
[When dealing with user input, consider what error checking we should put in place, i.e. no negative values]
[Use formatted output, 2 decimal places, for currency]
[Consider that company names may be more than one word]
As sample data, for the company Apple, we can have the following stock information: Stock symbol:
Stock symbol: AAPL
Company name: Apple Inc.
Stock price: 130.90
and for Google, we have:
Stock symbol: GOOG
Company name: Alphabet Inc.
Stock price: 2001.00
RunStock.java
RunStock.java public class RunStock
{
publicstaticvoid main(String[] args) {
}
}//end of RunStock class
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
