(calculating Sales) an online retailer sells five products whose retail prices are as follows:
Product 1, $2.98; product 2, $4.50, product 3, $9.98; product 4, $4.49 and product 5, $6.87.
Write an application tht reads a series of numbers as follows:
a) product number
b) quantatity sold
Your 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.
1
Expert's answer
2012-02-24T10:42:29-0500
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: ");
Comments
Leave a comment