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...
-
Carl Fenson of Winnipeg owned three taxicabs that operated for 24 hours a day (two shifts of 12 hours). Fenson worked one shift himself and hired drivers for the other shifts. At the time, in...
-
At the beginning of the current fiscal year, the balance sheet of Cummings Co. showed liabilities of $657,000. During the year, liabilities decreased by $108,000, assets increased by $231,000, and...
-
On 1 March 19X6, C Black, Curzon Road, Stockport, sold the following goods on credit to J Booth, 89 Andrew Lane, Stockport SK1 1AA, Order No 1697: (a) Prepare the sales invoice to be sent to J Booth....
-
Durham Companys trial balance as of January 1, the beginning of the current year, is given below: Durham Company uses a job-order costing system. During the year, the following transactions took...
-
A firm currently has a capital structure with 25 % debt. The debt, which is virtually riskless, pays an interest rate of 3 %. The expected rate of return on the equity 12 %. a) What is the...
-
Telstar uses job order costing. The T-accounts below summarize its production activity for the year. 1. Compute the amount for each of the following. a. Direct materials used b. Indirect materials...
-
1. Show two effects that have actually been experienced by Singapore, due to the collapse of US banks this year. Evidence should be given to prove the presence of each effect. 2. Analyse one factor...
-
How do the Basel III regulations impact global banking practices, particularly in terms of capital adequacy and stress testing?
-
3. John Dalton knew of the existence of at least three Oxides of Nitrogen. At the time, these were known as: Nitrous Gas, Nitrous Oxide and Nitric Acid. Nitrogen reacts with 1.000g of Oxygen in the...
-
Discuss RAFIKI (2018) in consideration of Ellerson's (2019) idea of the right of women to have power over their own bodies and desires and intimacies. How did director Wanuri Kahiu demonstrate...
-
At the start of a new project, Do Right (DR) Construction sent a series of five draft contracts to The Bidwell Group in which Bidwell was listed as the contracting party. While none of the contracts...
-
1. Imagine that as you are walking through campus someone yells your name. Describe the typical process of how you will sense and process this auditory information through the ear. Include a...
-
QUESTION 4 A. Perotiga Bhd is a company involved in automotive industry located in Southern Malaysia since 1998. Perotiga Bho plans to expand its business by having another factory building in...
-
Explain how the graph of each function can be obtained from the graph of y = 1/x or y = 1/x 2 . Then graph f and give the (a) Domain (b) Range. Determine the largest open intervals of the domain over...
-
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 =
-
Correctly apply the rules for the order of operations to accurately compute \(\left(\frac{5}{7}-\frac{2}{7} ight) \times 2^{3}\).
-
James is mixing soil for a raised garden, in which he plans to grow a variety of vegetables. For the soil to be suitable, he determines that \(\frac{2}{5}\) of the soil can be topsoil, but...
-
Correctly apply the rules for the order of operations to accurately compute \(4+\frac{2}{3} \div\left(\left(\frac{5}{9} ight)^{2}-\left(\frac{2}{3}+5 ight) ight)^{2}\).
Study smarter with the SolutionInn App