PROGRAM INSTRUCTIONS: 1. Create a program that calculates the cost of intended stock purchases. 2. Work and submit this…

PROGRAM INSTRUCTIONS: 1. Create a program that calculates the cost of intended stock purchases. 2. Work and submit this…

Question:

Transcribed Image Text:

PROGRAM INSTRUCTIONS: 1. Create a program that calculates the cost of intended stock purchases. 2. Work and submit this PA on your own (no partner). 2023 Linda Shepherd 3. Commenting Your Program: Refer to the Java Style Guide posted in Canvas for more commenting and formatting details. Java doc comment box examples are given to you in PowerPoint slides and may have been given to you in demo programs coded during class or through a video posted by your professor. TOC a. In your program, YOU MUST insert a program purpose in the first comment box. The content of that first comment box was shown to you in the Anatomy of a Java Program lecture for chapter 1. b. Use Javadoc comment boxes beginning with /** and ending with */ for your comment boxes. c. Insert a Javadoc comment box above all your methods explaining what is going on with the c. Insert a Javadoc comment box above all your methods explaining what is going on with the code in the method. d. Line comment the import statements and the variables declared at the class level and/or in any method [including main()]. e. Line comment close braces. The close brace for an else in an if-else is where you line comment for the structure. Line comment after the while in a do-while. 4. Formatting Rules: Always test to validate your program is functioning properly with the correct output and spacing (line advances and spacing after punctuation) in the output. The %n can function differently when using separate printf() statements versus one printf(). 5. UML Class Diagram: Data members are variables. The variables can be derived from the prompts and/or the final output. The complete code for the PA is outlined in logical progression within this UML. Class Name YourLastNameFirstInitialYourSectionNOPA1 Example: ShepherdL001PA1 Class N/A Data P Members Method input: Scanner: Data Members date, customerName: String shares, noStocks: int sharePrice, stockCost, commission, totalCost, onlineFee, dateTime: Calendari totalStockCost, total Commissions, totalOnlineFees: double onlineTrade, brokerAssisted, another: char Methods +main (args: String[]): static void PROMPTS: Code what is in bold. from the prompts below in printf() statements for capturing data. The actual output is not in bold. The prompts tell you your input variables. Except for the first two prompts, all the other ones reside within the while loop. 2023 Linda Shepherd YEE-TRADE, INC. The Wild West of Electronic Trading Welcome to Yee-Trade’s stock cost calculator. 4st Drompt. This primes con contralveriable another before 3 TOC YEE-TRADE, INC. The Wild West of Electronic Trading Welcome to Yee-Trade’s stock cost calculator. 1st Prompt: This primes the sentinel-loop control variable another before entering the while that controls the calculation for each stock cost. Enter ‘Y’ to begin stock cost calculations or ‘N’ to exit: 2nd Prompt: If another is ‘Y’ then ask for the customer’s name. D What is your name? If the answer is anything other than ‘Y’, the while loop is by-passed along with the remaining prompts, and no final output is displayed other than this message: Thank you for using Yee-Trade’s stock purchase calculator! 3rd Prompt: This is the next prompt when the answer to prompt 2 is Y. How many shares do you want to purchase? 4th Prompt: What is the price per share? 5th Prompt: If the answer to this prompt is ‘Y’ process for the online trading fee then go to the 7th prompt else ao to the 6th prompt. 5th Prompt: If the answer to this prompt is ‘Y’ process for the online trading fee then go to the 7th prompt, else go to the 6th prompt. Is this an online trade? Enter ‘Y’ or ‘N’: 6th Prompt: This prompt will display when the answer to the 5th prompt is anything other than ‘Y’. If the answer to this prompt is ‘Y’, calculate the commission by assessing a 2% brokerage fee on the stock cost then go to the 7th prompt, else proceed to the error message. 85 Is this a broker assisted trade? Enter ‘Y’ or ‘N’: Error Message When Trade is Neither Online or Broker Assisted: If the answer is ‘N’ to the 5th and 6th prompts, print this error message then proceed to the 7th prompt. “INVALID TRADE TYPE!” 7th Prompt: If the answer is ‘Y’ then you’ll go back to the 3rd prompt. This is the same loop-control variable in prompt 2. Enter ‘Y’ to calculate the cost for another stock or ‘N’ to exit: If the answer is anything other than ‘Y’, the while loop is exited, the final output is displayed if noStocks is greater than 0 then the thank you message is printed: Thank you for using Yee-Trade’s stock cost calculator! Sequencing and Logical Control: The following instructions give you the logical order of the code. The nesting of the logical structures and their Java statements are indented. 1. Declare and properly initialize variables. 2. Print the headers (company name and welcome message). 3. Prompt 1. 4. Code Prompt 2 in an if as long as another is ‘Y’ L For more 5. Use a sentinel-controlled while loop to process multiple stock cost calculations controlled by another as long as it is ‘Y’. a. Pre-increment noStocks. b. Prompt 3. c. Prompt 4. d. Calculate the stockCost, totalStockCost, and totalCost using combined assignment operators for the addition. e. Prompt 5. f. If it is an online Trade, assign 5.95 to onlineFee, calculate the totalOnlineFees and totalCost using combined assignment operators for e. Prompt 5. f. If it is an online Trade, assign 5.95 to onlineFee, calculate the totalOnlineFees and totalCost using combined assignment operators for the addition. g. Otherwise, OPY i. Prompt 6. ii. If it is a brokerAssisted trade, then calculate the commission, totalComissions, and totalCost using combined assignment operators for the addition. 1) Otherwise, a) print “INVALID TRADE TYPE!”. b) pre-decrement noStocks. c) deduct stockCost from totalStockCost and totalCost using combined assignment operators. h. Prompt 7. 6. Print the final output when noStocks is greater than 0. Here is the printf statement with alignment values. Appendix I posted with this PA is a good. resource for formatted output. System.out.printf(“%n%nYEE-TRADE, INC.” + “%n TOTAL COST OF INTENDED STOCK PURCHASES” + “%nFOR %s” 5 + “%nAS OF %s” 1/3 spaces before the format specifiers through commissions. + “%n%n Total Stock Cost: $%,14.2f” + “%n Total Online Fees: %14s” + “%n Total Commissions: %14s” /19 spaces before the format specifier for TOTAL COST. + “%n%n TOTAL COST: $%,14.2f%n”, customerName, date, totalStockCost, String.format(“%.2f”, totalOnlineFees), String.format(“%,. 2f”, totalCommissions), totalCost); 7. Print the “Thank you…” message. 8. Zero out noStocks. 9. Exit. 10. The Prompts, the output specs, and the sample output show you in what order to place your code. To return from these links press Alt, left arrow. TOC HERS 11. You are to generate output from your program according to the instructions in the sample output section. OUTPUT SPECIFICATIONS: The Xs in the 3rd header is the customer’s name. The Xs in the der is the month name (all capitalized) followed by the two 9s for the day and the four 9s for r. The Zs and 9s represent the output as formatted numbers. Zs indicate suppression of zeroes. The 9s indicate the printing of a digit even a 0. Use System.out.printf() and the riate format specifiers. NOTE: The final output is only displayed when there are stocks

Expert Answer: