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
Hi everyone can anyone tell me how to align the photo the right in code.org
Ostrovityanka [42]

Answer:

Step 1: Wrap the image in a div element. Step 2: Set the display property to "flex," which tells the browser that the div is the parent container and the image is a flex item. Step 3: Set the justify-content property to "right." Step 4: Set the width of the image to a fixed length value

Explanation:

6 0
2 years ago
Where do you place the logical test argument in an JF function formula?
balandron [24]

Answer:

the first argument listed after IF

Explanation:

The Logical... argument in an IF function formula is always the first argument listed after IF.  And the second option is the value to be printed if the logical...argument is true, and if it is false then the value mentioned as third argument is assigned, or printed. And the logical...argument never comes before the IF function formula. Hence, the right option is the first argument.

7 0
3 years ago
Read 2 more answers
Why do my airpods keep disconnecting from my laptop
user100 [1]
Hmm well maybe there is bad Bluetooth connection coming from the laptop
7 0
2 years ago
Read 2 more answers
How can a search be narrowed to only search a particular website????
vesna_86 [32]

Answer:

There are a variety of ways to narrow down your search results in a library database. The two most direct ways are to focus your search with more specific keywords and/or to limit by various criteria before or after searching. The more specific you are with your search terms, the more relevant your results will be

Hope it helped!!!

4 0
3 years ago
Documental acerca de los principales materiales que se emplean en la fabricación de medios técnicos utilizados en una oficina.
Diano4ka-milaya [45]

Answer:

Los equipos técnicos utilizados en una oficina y los principales materiales utilizados en su fabricación son;

Equipo de oficina {}    Material utilizado en la fabricación

1) Impresoras;           {}    Acero, aluminio, alambres de cobre, plástico, rodillos

2) Monitor de computadora; {}   Pantalla de vidrio, plástico, cables, placas de circuito, resortes

3) Escáneres;     {}  Alfombra compuesta, mesa de vidrio, carcasa de plástico, cables

4) Copiador;   {}       Carcasa de plástico, contenedor de tóner, placa de vidrio, cables de alimentación

5) Proyector;    {}    Lente de vidrio y carcasa de metal para lámpara, cables de alimentación

6) Desfibradora; {}    Engranajes de plástico, correa de cadena de metal, rodamientos

Explanation:

4 0
2 years ago
Other questions:
  • Random-access memory (RAM) is able to quickly access data because it is arranged in which of the following configurations?
    8·2 answers
  • The concept of vertical farming allows agriculture to occur when there is not enough___Available .
    13·1 answer
  • Look at the following form. Which input method is the form using to receive the user's favorite activity? What is your favorite
    12·2 answers
  • If you press the key corresponding to letter A on the keyboard, what process is carried out inside the CPU to display the letter
    10·1 answer
  • In the 1880’s advancements in technology and processes made photography available to the general public. Who is considered the m
    12·1 answer
  • What is the output of the following program? If there is any problem, how can
    13·1 answer
  • Name any four areas where computers are used​
    15·1 answer
  • 2. The<br>is the main and usually largest data storage hardware device in a computer​
    9·1 answer
  • A program similar to mtr, ____, is available as a command-line utility in Windows operating systems.
    12·1 answer
  • What are some qualities of a good game critic? What are some qualities of a bad game critic?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!