You are interested in investing in some stock. You find that the best stocks for this...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
You are interested in investing in some stock. You find that the best stocks for this year include the companies listed below: Company Stock Price (U.S.) Starbucks NXP Semiconductors $85.77 $117.41 Facebook $202.00 Stitch Fix $23.97 Johnson & Johnson $137.75 Nike $94.14 Centene Corporation $60.44 Apple $267.84 Sprouts Farmer's Market $19.45 DuPont $65.61 Create a class that references the data provided. Remember the naming rule: All class and method names should include your initials at the end of the name. You will need: 1. Private members to store: The company name (String) The price per stock (double) The amount of stock to purchase (int) 2. A static private member called totalCost (of type double) to store the total cost of all shares among all companies (initialized to 0) 3. A constructor that accepts the name of the company and the amount of stock to be purchased. • The constructor will call one private method: setStockPrice to set the price of each stock per company 4. A private method called setPrice which accepts no parameters and returns no values. The method will also contain a switch statement that creates a case for each company. No default case is needed. The expression of the switch statement should use the tolowerCase method to change the company name to lower case. o An example of how to set up your switch is shown below: switch (name.toLowerCase()) case "apple": price = 267.84: break; //complete the switch 5. A private method called calCost that accepts no parameters but returns a double value. • Cost = price of stock * amount of stock • In this method, update the value of totalCost (by adding cost to it) • The cost of each stock, NOT totalCost will be returned by this method 6. A public and static method called getTotalCost that accepts no parameters, but returns the totalCost of all the stocks among all the companies 7. AtoString method that: Outputs the company name, price per stock, and the cost for the amount of stock purchased 8 For the cost, call the calCost method you created from within this method Formats the prices to currency (You need to include a NumberFormat object here) Formats the output using the format method from the String class so that the output looks neat and presentable. An example of how to set that up is shown below: String.format("&-20s", name) Additionally, you will create a driver program that uses your version of the BestStocks class. You will need: 1. To prompt the user for the number of companies whose stocks they are interested in. • Use input validation to ensure that the user enters a value greater than or equal to 1 for the amount of companies. 2. Local variables to store the company name, and the amount of stock to be pruchased • Let's presume that the user enters one of the ten companies listed. 3. To create an array of BestStocks objects, using the value from the amount of companies • Example if three companies are selected the array of objects will be of size 3. 4. A loop to ask the user for the company name and the amount of stock The loop should be limited by the amount of companies Use input validation to ensure that the user enters a value greater than or equal to 1 for the amount of stock The loop must include syntax that instantiates each object once the company name and amount of stock are provided 5. Outputs the information for each BestStock object 6. Outputs the totalCost of all the shares among all the companies Call the static method getTotalCost from your BestStocks class here • Format the total cost using a NumberFormat object Tip: Do not attempt the format the static variable, as this can cause a syntax error. Samples of the output are shown below: Sample Output 1- (with correct values) How many companies' stocks are you interested in? Amount must be >= 1: Enter name of company 1: Nike Enter amount of stock (>= 1) for Nike: 150 Enter name of company 2: Sprouts Farmer's Market Enter amount of stock (>= 1) for Sprouts Farmer's Market: 250 Enter name of company 3: Stitch Fix Enter amount of stock (>= 1) for Stitch Fix: 100 Enter name of company 4: Starbucks Enter amount of stock (>= 1) for Starbucks: 200 Your companies and stocks are: Nike Sprouts Farmer's Market Stitch Fix Starbucks The total amount is: $38,534.50 $14,121.00 $4,862.50 $2,397.00 $17,154.00 $94.14 $19.45 $23.97 $85.77 Sample Output 2 - (with input validation) How many companies stocks are you interested in? Amount must be >= 1: How many companies stocks are you interested in? Amount must be >= 1: 3 Enter name of company 1: DuPont Enter amnount of stock (>= 1) for DuPont: Amount of stock must be greater than or equal to 1. Re-enter amount of stock for DuPont: 50 Enter name of company 2: Centene Corporation. Enter amount of stock (>= 1) for Centene Corporation: 75 Enter name of company 3: Facebook Enter amount of stock (>= 1) for Facebook: 40 Your companies and stocks are: $65.61 $60.44 $202.00 $3,280.50 $4,533.00 $8,080.00 DuPont Centene Corporation Facebook The total amount is: $15,893.50 Extra Credit (10 points): Use Dialog Boxes to read in and display your output in your version of the BestStocks Driver program! You are interested in investing in some stock. You find that the best stocks for this year include the companies listed below: Company Stock Price (U.S.) Starbucks NXP Semiconductors $85.77 $117.41 Facebook $202.00 Stitch Fix $23.97 Johnson & Johnson $137.75 Nike $94.14 Centene Corporation $60.44 Apple $267.84 Sprouts Farmer's Market $19.45 DuPont $65.61 Create a class that references the data provided. Remember the naming rule: All class and method names should include your initials at the end of the name. You will need: 1. Private members to store: The company name (String) The price per stock (double) The amount of stock to purchase (int) 2. A static private member called totalCost (of type double) to store the total cost of all shares among all companies (initialized to 0) 3. A constructor that accepts the name of the company and the amount of stock to be purchased. • The constructor will call one private method: setStockPrice to set the price of each stock per company 4. A private method called setPrice which accepts no parameters and returns no values. The method will also contain a switch statement that creates a case for each company. No default case is needed. The expression of the switch statement should use the tolowerCase method to change the company name to lower case. o An example of how to set up your switch is shown below: switch (name.toLowerCase()) case "apple": price = 267.84: break; //complete the switch 5. A private method called calCost that accepts no parameters but returns a double value. • Cost = price of stock * amount of stock • In this method, update the value of totalCost (by adding cost to it) • The cost of each stock, NOT totalCost will be returned by this method 6. A public and static method called getTotalCost that accepts no parameters, but returns the totalCost of all the stocks among all the companies 7. AtoString method that: Outputs the company name, price per stock, and the cost for the amount of stock purchased 8 For the cost, call the calCost method you created from within this method Formats the prices to currency (You need to include a NumberFormat object here) Formats the output using the format method from the String class so that the output looks neat and presentable. An example of how to set that up is shown below: String.format("&-20s", name) Additionally, you will create a driver program that uses your version of the BestStocks class. You will need: 1. To prompt the user for the number of companies whose stocks they are interested in. • Use input validation to ensure that the user enters a value greater than or equal to 1 for the amount of companies. 2. Local variables to store the company name, and the amount of stock to be pruchased • Let's presume that the user enters one of the ten companies listed. 3. To create an array of BestStocks objects, using the value from the amount of companies • Example if three companies are selected the array of objects will be of size 3. 4. A loop to ask the user for the company name and the amount of stock The loop should be limited by the amount of companies Use input validation to ensure that the user enters a value greater than or equal to 1 for the amount of stock The loop must include syntax that instantiates each object once the company name and amount of stock are provided 5. Outputs the information for each BestStock object 6. Outputs the totalCost of all the shares among all the companies Call the static method getTotalCost from your BestStocks class here • Format the total cost using a NumberFormat object Tip: Do not attempt the format the static variable, as this can cause a syntax error. Samples of the output are shown below: Sample Output 1- (with correct values) How many companies' stocks are you interested in? Amount must be >= 1: Enter name of company 1: Nike Enter amount of stock (>= 1) for Nike: 150 Enter name of company 2: Sprouts Farmer's Market Enter amount of stock (>= 1) for Sprouts Farmer's Market: 250 Enter name of company 3: Stitch Fix Enter amount of stock (>= 1) for Stitch Fix: 100 Enter name of company 4: Starbucks Enter amount of stock (>= 1) for Starbucks: 200 Your companies and stocks are: Nike Sprouts Farmer's Market Stitch Fix Starbucks The total amount is: $38,534.50 $14,121.00 $4,862.50 $2,397.00 $17,154.00 $94.14 $19.45 $23.97 $85.77 Sample Output 2 - (with input validation) How many companies stocks are you interested in? Amount must be >= 1: How many companies stocks are you interested in? Amount must be >= 1: 3 Enter name of company 1: DuPont Enter amnount of stock (>= 1) for DuPont: Amount of stock must be greater than or equal to 1. Re-enter amount of stock for DuPont: 50 Enter name of company 2: Centene Corporation. Enter amount of stock (>= 1) for Centene Corporation: 75 Enter name of company 3: Facebook Enter amount of stock (>= 1) for Facebook: 40 Your companies and stocks are: $65.61 $60.44 $202.00 $3,280.50 $4,533.00 $8,080.00 DuPont Centene Corporation Facebook The total amount is: $15,893.50 Extra Credit (10 points): Use Dialog Boxes to read in and display your output in your version of the BestStocks Driver program!
Expert Answer:
Answer rating: 100% (QA)
CODE import javaio import javatextNumberFormat import javautil BestStocks class public class BestStocks member variable declaration private String com... View the full answer
Related Book For
Posted Date:
Students also viewed these mathematics questions
-
The graph below is called a double line graph (or a double broken-line graph.) Use this graph for below Exercises. 1. Overall, is the number of BEVs sold in the United States increasing or...
-
The price-earnings ratios for all companies whose shares are traded on the New York Stock Exchange follow a normal distribution with a standard deviation of 3.8. A random sample of these companies is...
-
The graph illustrates an average total cost (ATC) curve (also sometimes called average cost), marginal cost (MC) curve, average variable cost (AVC) curve, and marginal revenue (MR) curve (which is...
-
The following are selected 2023 transactions of Ayayai Corporation. Sept. 1 Oct. 1 1 Purchased inventory from Indigo Ltd. on account for $47,200. Ayayai uses a periodic inventory system. Issued a...
-
Provide a mechanism that explains formation of the following products. OMe MeOH +CI OMet
-
The adjusted trial balance columns of the worksheet for Bleecker Street, Ltd., owned by Raymond Pearson, are as follows. Instructions (a) Complete the worksheet by extending the balances to the...
-
Consider a random walk \(\left\{y_{t} ight\}\) as the partial sum of a white noise process \(\left\{c_{t} ight\}\). a. Show that the \(l\)-step forecast error is...
-
Float and Weighted Average Delay your neighbor goes to the post office once a month and picks up two checks, one for $13,000 and one for $4,000. The larger check takes four days to clear after it is...
-
In an initial discussion forum post, describe the key elements of channel design and business service marketing. Next, explain why it is important for a marketing manager to understand business...
-
In early 2016, Doc and Lyn McGee formed the McGee Cake Company. The company produced a full line of cakes, and its specialties included chess cake,* lemon pound cake, and double-iced, double...
-
How can Philip, who works as a full-time professor at GBC and who operates his part-time consulting business during the summer as a sole proprietorship, use his knowledge of marginal tax rates to...
-
There is an increase in the quantity of gasoline exchanged in the market, but the price remains the same. What must have happened to supply and demand?
-
The rpi specifies the rate at which the module being configured sends?
-
What can you determine about a file by looking at its properties?
-
For Tax Year 2022, what is the amount employers are required to withhold from an employee's gross pay for social security tax and medicare tax?
-
Accountant 14 is a tax senior. LMN is a new client for us. He just found an error in the lastyear's tax return and LMN owes IRS a lot of money. He believes he should amend the returnbut LMN refuses....
-
Internet 2. The percent of Americans that use the internet is shown in the table. 1990 year 0 a. Find the linear equation of the line passing through years 1995 and 2001 by hand (2 places for final...
-
Explain what is meant by vicarious liability and when it is available?
-
Use a calculator to find the length of the curve correct to four decimal places. If necessary, graph the curve to determine the parameter interval. (a) One loop of the curve r = cos 2 (b) r = sin (6...
-
Find an equation of the curve that passes through the point (0, 1) and whose slope at (x, y) is xy.
-
If Where is a continuous function, find f(4). f(t) dt. xsin TX =
-
Someone who exposes the ethical misdeeds of others in an organization is usually called a/an _________. (a) whistleblower (b) ethics advocate (c) ombudsman (d) stakeholder
-
Two employees are talking about ethics in their workplaces. Jay says that ethics training and codes of ethical conduct are worthless; Maura says they are the only ways to ensure ethical behavior by...
-
If a manager takes a lot of time explaining to a subordinate why he did not get a promotion and sincerely listens to his concerns, this is an example of an attempt to act ethically according to...
Study smarter with the SolutionInn App