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
Which service enables administrators to execute a command on remote computers using windows powershell or the windows remote she
Anvisha [2.4K]
Remote Assistance is the answer.
4 0
3 years ago
Hello can you please help with this if you want to thank you!
nikklg [1K]

Answer:

hardware and software is the answer

8 0
3 years ago
Read 2 more answers
What is elif? How does it work in python?
pav-90 [236]
It is the condition used after the if condition. say you use the if condition and you need to add another outcome, instead of using the if condition again, you’d use elif and end it with the else command.

example:

if num == 10:
print (“correct”)

elif num > 10:
print (“too high”)

else:
print (”too low”)

hope this helps :]
5 0
3 years ago
Read 2 more answers
How does an ALU perform a logical operation? A. It compares two conditions. B. It compares two additions. C. It compares two mul
german
A.It compares two conditions
6 0
3 years ago
Read 2 more answers
"To speed up magnetic hard drive performance , ___________ is often used. "
Harrizon [31]

Answer:

disk caching

Explanation:

Hi,

Magnetic hard drives use disk caching to speed up performance. This method is quite ingenious because what it does is that in a section of memory in your pc, it keeps a copy of information that was previously accessed in the hard disk. So, next time if the same data is requested, the system can refer to cache to get quick access rather than going to the hard disk (which is slower).

3 0
3 years ago
Other questions:
  • Bugs bunny personality traits
    7·1 answer
  • Suppose sum and num are int variables, and the input is 18 25 61 6 -1
    11·2 answers
  • Reversing the elements of an array involves swapping the corresponding elements of the array: the first with the last, the secon
    11·1 answer
  • Write a script that calculates the common factors between 8 and 24. To find a common factor, you can use the modulo operator (%)
    14·1 answer
  • Which of the following peripheral devices can be used for both input and output? mouse touch screen on a tablet computer printer
    5·1 answer
  • Jenny, a programmer, uses Microsoft Excel 2016 to generate data required for the programs she develops. She uses various functio
    10·1 answer
  • Which shooting games is good for low end PC. CSGO or Valorant?​
    11·1 answer
  • It is for employees to make mistakes that compromise the security of an organization’s computer devices and sensitive informatio
    10·2 answers
  • One security component that doubles as a network component
    5·2 answers
  • I NEED THIS DONE NOW ASAP, PLS HELP ME
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!