For this assignment write a Java application that prompts th

For this assignment, write a Java application that prompts the user for pairs of inputs of a product number (1-5), and then an integer quantity of units sold (these are two separate prompts for input values). Assignment Description: Write a Java program to process the 15 items below for a single order. 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) You must use a switch statement and a sentinel-controlled loop (i.e., a loop that stops execution when an out of range value, such as -1, is input). You must show all user inputs, including the product numbers, quantities, and sentinel value. You must also show all program outputs. Your application must calculate and display the cumulative total order amount after each of the five pairs of input values is entered. You must also show the total order amount after the sentinel value is entered. Only showing a subset of all the required inputs and outputs will result in lost points.

Solution

Hi, Please find my solution.

Please let me know in case of any issue.

import java.util.Scanner;

public class App {

   public static void main(String[] args) {

      

       Scanner sc = new Scanner(System.in);

       int[] productQuantity = new int[5];

       double[] unitPrice = {2.98, 4.50, 9.98, 4.49, 6.87};

       double[] totalPrice = new double[5];

      

       double totalComulativePrice = 0;

      

       int prodt;

       int quantity;

      

       while(true){

          

           System.out.print(\"Enter product number: \");

           prodt = sc.nextInt();

          

           if(prodt>5 || prodt < 1) // if product number is out of range, then stop

               break;

          

           System.out.print(\"Enter quantity sold: \");

           quantity = sc.nextInt();

          

           if(quantity < 0) // if quantity entered is less than 0 then stop

               break;

          

           switch(prodt){

          

           case 1:

               productQuantity[0] += quantity; // adding quantity sold

               totalPrice[0] += quantity*unitPrice[0];

               break;

           case 2:

               productQuantity[1] += quantity; // adding quantity sold

               totalPrice[1] += quantity*unitPrice[1];

               break;

           case 3:

               productQuantity[2] += quantity; // adding quantity sold

               totalPrice[2] += quantity*unitPrice[2];

               break;

           case 4:

               productQuantity[3] += quantity; // adding quantity sold

               totalPrice[3] += quantity*unitPrice[3];

               break;

           case 5:

               productQuantity[4] += quantity; // adding quantity sold

               totalPrice[4] += quantity*unitPrice[4];

               break;

           }

          

           totalComulativePrice += quantity*unitPrice[prodt-1]; // adding current product price in total

       }

      

       System.out.println(\"Product number 1 is sold \"+productQuantity[0]+\" number of quantity for $\"+totalPrice[0]);

       System.out.println(\"Product number 2 is sold \"+productQuantity[1]+\" number of quantity for $\"+totalPrice[1]);

       System.out.println(\"Product number 3 is sold \"+productQuantity[2]+\" number of quantity for $\"+totalPrice[2]);

       System.out.println(\"Product number 4 is sold \"+productQuantity[3]+\" number of quantity for $\"+totalPrice[3]);

       System.out.println(\"Product number 5 is sold \"+productQuantity[4]+\" number of quantity for $\"+totalPrice[4]);

      

       System.out.println(\"Entered sentinal value is : \"+prodt);

      

       System.out.println(\"Total commulative total is $\"+totalComulativePrice);

      

   }

}

/*

Sample Output:

       Enter product number: 1

       Enter quantity sold: 1

       Enter product number: 2

       Enter quantity sold: 2

       Enter product number: 3

       Enter quantity sold: 3

       Enter product number: 4

       Enter quantity sold: 4

       Enter product number: 5

       Enter quantity sold: 5

       Enter product number: -1

       Product number 1 is sold 1 number of quantity for $2.98

       Product number 2 is sold 2 number of quantity for $9.0

       Product number 3 is sold 3 number of quantity for $29.94

       Product number 4 is sold 4 number of quantity for $17.96

       Product number 5 is sold 5 number of quantity for $34.35

       Entered sentinal value is : -1

       Total commulative total is $94.23

*/

For this assignment, write a Java application that prompts the user for pairs of inputs of a product number (1-5), and then an integer quantity of units sold (t
For this assignment, write a Java application that prompts the user for pairs of inputs of a product number (1-5), and then an integer quantity of units sold (t
For this assignment, write a Java application that prompts the user for pairs of inputs of a product number (1-5), and then an integer quantity of units sold (t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site