Write a Java application that prompts the user for pairs of inputs of a product
ID: 3637440 • Letter: W
Question
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 (this is two separate prompts for input values). 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). 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 of all products sold, after all 5 pairs of inputs are completed. You must also display the total after each new pair of input values is entered.
Explanation / Answer
The following source code will help you for your above question as i think
import javax.swing.*;
import java.util.Scanner;
public class Program2
{
public static void main(String[] args)
{
final int NUMBER_OF_ITEMS = 5;
int[] productNum = { 1, 2, 3, 4, 5};//array of product number
double[] price = { 2.98, 4.50, 9.98, 4.49, 6.87};//array of price
double quantity, product, total;
Scanner imput = new Scanner(System.in);
System.out.print("Enter Product Number (1-5) or -1 to Quit:");
productNum = input.nextInt();.out.print("Enter Quantity:");
quantity = input.nextDouble();
total = product * quantity;
System.out.print(total);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.