90 068
Assignments Done
99.7%
Successfully Done
In September 2020

# Answer to Question #16550 in Java | JSP | JSF for Nancy

Question #16550
An online retailer sells five products whose retail prices are as follows:

Product 1, $2.98 Product 2,$4.50
Product 3, $3.98 Product 4,$4.49
Product 5, $6.87 Write an application that reads (from the keyboard) a series of pairs of numbers as follows: product number quantity sold Run your program from a simple menu with the following options Enter products sold Display total retail value Exit Your program should allow for entry of multiple products without returning to the main menu (use a sentinel-controlled loop) use a switch statement to determine the retail price for each product calculate and display the total retail value of all products sold 1 Expert's answer 2012-10-16T09:40:07-0400 import java.util.Scanner; public class Store { public static void main(String[] args) { Scanner in = new Scanner(System.in); int choice; double product1 = 0, product2 = 0, product3 = 0, product4 = 0, product5 = 0, total = 0; do { System.out.println(&quot;Enter product # (0 to quit): &quot;); String tempChoice = in.nextLine(); choice = Integer.parseInt(tempChoice); switch (choice) { case 1: System.out.println(&quot;Enter product quantity: &quot;); String tempQuantity = in.nextLine(); product1 += Integer.parseInt(tempQuantity) * 2.98; total += product1; break; case 2: System.out.println(&quot;Enter product quantity: &quot;); tempQuantity = in.nextLine(); product2 += Integer.parseInt(tempQuantity) * 4.50; total += product2; break; case 3: System.out.println(&quot;Enter product quantity: &quot;); tempQuantity = in.nextLine(); product3 += Integer.parseInt(tempQuantity) * 3.98; total += product3; break; case 4: System.out.println(&quot;Enter product quantity: &quot;); tempQuantity = in.nextLine(); product4 += Integer.parseInt(tempQuantity) * 4.49; total += product4; break; case 5: System.out.println(&quot;Enter product quantity: &quot;); tempQuantity = in.nextLine(); product5 += Integer.parseInt(tempQuantity) * 6.87; total += product5; break; } } while (choice != 0); System.out.println(&quot;Sum of product 1 sold:$&quot; + product1);

System.out.println(&quot;Sum of product 2 sold: $&quot; + product2); System.out.println(&quot;Sum of product 3 sold:$&quot; + product3);

System.out.println(&quot;Sum of product 4 sold: $&quot; + product4); System.out.println(&quot;Sum of product 5 sold:$&quot; + product5);

System.out.println(&quot;Total sold : \$&quot; + total);

}

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS