60 503
Assignments Done
98,1%
Successfully Done
In April 2018

Answer to Question #6853 in Java | JSP | JSF for Prezy Olayo

Question #6853
(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.
Expert's answer
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);

}




}

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!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions