Write a Java application that prompts the user for pairs of inputs of a product number (1,2,3,4,5) and quantity of units sold (any integer)?
Use a
switchstatement and a sentinel-controlled loop (i.e., a loop that stops execution when an out-of-range value, such as -1, is input).All 15 items below are for a single purchase. There are five sets of inputs as follows:
Product 1 1 unit (cost is $2.98 per unit) Product 2 2 units (cost is $4.50 per unit) Product 3 3 units (cost is $9.98 per unit) Product 4 4 units (cost is $4.49 per unit) Product 5 5 units (cost is $6.87 per unit)Your application must calculate and display the total retail value for all the five pair of products sold.
import java.util.Scanner; public class Program3 { Scanner input = new Scanner (System.in); public static void main(String[] args) { int productNo = 0; double product1; double product2; double product3; double product4; double product5; int quantity; double totalSales = 0; while(productNo !=0 ) System.out.println("Enter product number 1-5 "); productNo=input.nextInt(); System.out.println("Enter quantity sold "); quantity = input.nextInt(); switch (productNo) { case 1: product1 = 2.98; totalSales+=(2.98*quantity); break; case 2: product2 = 4.50; totalSales+=(4.50*quantity); break; case 3: product3 = 9.98; totalSales+=(9.98*quantity); break; case 4: product4 = 4.49; totalSales+=(4.49*quantity); break; case 5: product5 = 6.87; totalSales+=(6.87*quantity); break; } System.out.println(totalSales); }