Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is making me crazy, I cannot figure out what I am doing wrong. Assignment:

ID: 3529111 • Letter: T

Question

This is making me crazy, I cannot figure out what I am doing wrong. Assignment: An online retailer sells five products whose prices are: Pro 1, $2.98, Pro 2, $4.50, Pro 3, $9.98, Pro 4, $4.49, Pro 5, $6.87. Write an application that reads a series of pairs of numbers as follows: a) product number, b) quantity sold. Program should use a switch statement to determine the retail price for each product. It should calculate and display the total retail value of all products sold. Use a sentinel controlled loop to determine when the program should stop looping and display the final results. Professor has added: Prompt the user for input until the user enters 0 as a sentinel value to stop and then calculate the retail value of the 5 products. Do not accept a product number less than 0 or greater than 5. Here is what I have: /*CIS-171-OL01 Annette Beason 2/22/1013 Chapter5, p. 194*/ import java.util.Scanner; public class product { public static void main(String [] args) { Scanner input = new Scanner(System.in); int productNumber=0; int quantity=0; int price=0; int totalPrice=0; double price; double totalPrice; double total; } while (productNumber >=1 || productNumber <=5) //error message is here, illegal start of type, identifier expected// { System.out.println ("Product number: "); product = input.nextInt(); System.out.println ("Quantity: "); quantity = input.nextInt(); switch (productNumber) { case 1: total += 2.98 *quantity; break; case 2: total += 4.50 *quantity; break; case 3: total += 9.98 *quantity; break; case 4: total += 4.49 *quantity; break; case 5: total += 6.87 *quantity; break; } System.out.println ("To continue enter 1, To show total enter 2, To quit enter 0:"); choice = input.nextInt (); if (choice=2) { System.out.printf("%d TOTAL: "); } }} Am I anywhere near close to being correct here??

Explanation / Answer

Prefer this could help you for sure package sales; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner( System.in ); int prodNumber, quantity, choice = 1; double total = 0; while(choice != 2){ System.out.print("Product number: "); prodNumber = in.nextInt(); System.out.print("Quantity sold: "); quantity = in.nextInt(); switch(prodNumber){ case 1: total += 2.98*quantity; break; case 2: total += 4.5*quantity; break; case 3: total += 9.98*quantity; break; case 4: total += 4.49*quantity; break; case 5: total += 6.87*quantity; break; default: System.out.println("error: wrong number of product!"); break; } System.out.print("To continue enter 1, To show total enter 2: "); choice = in.nextInt(); } System.out.print(" TOTAL: "); System.out.println(total); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote