1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Korolek [52]
3 years ago
9

5.17 (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 that reads a series of pairs of numbers as follows: product number quantity 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.
Computers and Technology
1 answer:
Dima020 [189]3 years ago
4 0

Answer:

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

   

    //Initialize the prices as constants

    final double PRODUCT_1_PRICE = 2.98;

    final double PRODUCT_2_PRICE = 4.50;

    final double PRODUCT_3_PRICE = 9.98;

    final double PRODUCT_4_PRICE = 4.49;

    final double PRODUCT_5_PRICE = 6.87;

   

    //Declare the other variables

    int productNumber, quantitySold;

    double total = 0.0;

   

    //Create a Scanner object to get input

    Scanner input = new Scanner(System.in);

   

    //Create a while loop

    while(true){

        //Ask the user to enter the productNumber

     System.out.print("Enter the product number or 999 to quit: ");

     productNumber = input.nextInt();

     

     // Stop the loop, if productNumber is 999(sentinel value, you may choose any value you want)

     if(productNumber == 999)

         break;

     

     //Ask the user to enter the quantitySold

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

     quantitySold = input.nextInt();

     

     //Create a switch statement that works depending on the productNumber entered.

     //For example, if the productNumber is 1, it multiplies the quantitySold by PRODUCT_1_PRICE

     //   and adds the result to the total. If productNumber is 2, it does the same for product 2 ...

     switch(productNumber){

         case 1:

             total += quantitySold * PRODUCT_1_PRICE;

             break;

         case 2:

             total += quantitySold * PRODUCT_2_PRICE;

             break;

         case 3:

             total += quantitySold * PRODUCT_3_PRICE;

             break;

         case 4:

             total += quantitySold * PRODUCT_4_PRICE;

             break;

         case 5:

             total += quantitySold * PRODUCT_5_PRICE;

             break;

     }

    }

 

 //Print the total (when the loop is done)

 System.out.println("The total is $" + total);

}

}

Explanation:

*The code is in Java.

You may see the explanation as comments in the code.

You might be interested in
Paul is a chemical engineer working with large storage tanks of chemicals. Working from home using a program on his computer, he
gregori [183]
A pressure regulator application on his computer or a station nearbye
7 0
3 years ago
An individualized course plan for the 4 years of
spin [16.1K]

Answer:

.....

Explanation:

8 0
2 years ago
Read 2 more answers
In the story, what are the song pauses a metaphor for?
-BARSIC- [3]

Answer:

D. The need to slow down more often in life.

4 0
3 years ago
Write a program that accepts a whole number as
SashulF [63]

This is for Python

number = int(input('Number: '))

number = number * 12

print(number)

3 0
2 years ago
Do my Twitter posts count as opinions or facts?
elena55 [62]
They count as opinions
6 0
2 years ago
Read 2 more answers
Other questions:
  • A(n ____ is a named group of formatting characteristics.
    7·1 answer
  • While interoperability and unrestricted connectivity is an important trend in networking, the reality is that many diverse syste
    12·1 answer
  • Consider the following C++ program in which the statements are in the incorrect order. Rearrange the statements so that itprompt
    6·1 answer
  • What is the difference between amplifier and the repeater?
    11·1 answer
  • What should be used to screw on broadheads? needle-nose pliers gloves thumb and forefinger only specially designed wrench
    6·1 answer
  • What happens to a data table when the formulas or variables used to create it are changed?
    9·2 answers
  • When evaluating the validity of a website beyond its URL, you can practice the "rule of 3" which means
    11·2 answers
  • Two technicians are discussing a parasitic load test. Technician A says that the parasitic load is measured with an ammeter Tech
    13·1 answer
  • The {blank} view is the working window of a presentation.
    15·2 answers
  • Busco a talcotalco38
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!