Write a complete Java program named CalculateCost. It does t…
Write a complete Java program named CalculateCost. It does the following: It takes the user’s name as a command-line argument (e.g., java CalculateCost Trinity) It greets the user with a welcome message (e.g., “Hello Trinity!”). Note the exclamation mark. It asks the user how many products they want to buy. The user will always type a positive integer. It then reads that many integer numbers from the user, one number per line. The product options a user can enter per line are “pen” or “pencil”. A pen costs $2 and a pencil costs $1.25. The program keeps prompting for products until it has received the exact number of products provided by the user in the first prompt. It then calculates the total cost after taxes. The tax rate is 4% (calculated on the total cost, not on the individual products). The final cost should be rounded to two decimals. Finally, it prints the user’s name and the final cost using a single printf statement (e.g., “Trinity, the total is $4.68.”). Make sure the output formatting matches the example exactly. Example command: java Calculatecost Trinity Example console input/output (input in bold): Hello Trinity! Please enter the number of products: 3 pencil pen pencil Trinity, the total is $4.68. Canvas Tip: Click on the dropdown that says “Paragraph” and switch to “Preformatted” to get a monospaced font – this can help in coding answers.
Read Details