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
Define
3241004551 [841]

Computational thinking- the thought processes involved in formulating a problem and expressing its solution(s) in such a way that a computer—human or machine—can effectively carry out. Computational Thinking is an iterative process based on three stages.

Problem solving process- The process of working through details of a problem to reach a solution. Problem solving may include mathematical or systematic operations and can be a gauge of an individual's critical thinking skills.

Data- facts and statistics collected together for reference or analysis.

Information- facts provided or learned about something or someone.

Algorithm- a process or set of rules to be followed in calculations or other problem-solving operations, especially by a computer.

Aggregate data- aggregate data are data combined from several measurements. When data are aggregated, groups of observations are replaced with summary statistics based on those observations. In a data warehouse, the use of aggregate data dramatically reduces the time to query large sets of data.

Discovery Data- in the context of IT, is the process of extracting actionable patterns from data. The extraction is generally performed by humans or, in certain cases, by artificial intelligence systems.



3 0
3 years ago
(tco 7) the asp.net ajax client-side framework is loaded on the _____ for an asp.net web application.
jok3333 [9.3K]

a client-side framework is loaded on the client side, ie., the browser.

4 0
2 years ago
Give the imporntance of having standard funiture in the laboratory​
TEA [102]

Answer:

I guess if there is experiment going on in absence one of those furniture then the experiment isn't successful

8 0
3 years ago
For which product would the producer keep a high profit margin and offer after-sales service?
Zina [86]

What are the products?

6 0
3 years ago
Examples of ________, which is hosted on a web site, include e-mail, word processing, tax preparation, and game programs.
Keith_Richards [23]

Answer:Web Application

Explanation:Web hosting is more or less like having an ordinary computer in the cloud in order share information and resources with others world wide.One cannot make effective use of a computer without software applications . Similarly hosting just normal html pages and documents on a server cannot help increase productivity,hence the creation of cloud computer applications also known as "Web Apps (Web Applications)" to aid boost productivity and information dissemination via quality task automations.

4 0
2 years ago
Other questions:
  • Before starting a spreadsheet, it is smarter to plan ahead and think through the design. true or false
    13·1 answer
  • In internet terminology, what is the term, .com, called?
    12·2 answers
  • Consider the relation Courses(C, T, H, R, S, G), whose attributes can be thought of informally as course (C), teacher (T), hour
    10·1 answer
  • Header and Footer options are located in the _____ tab.
    7·1 answer
  • What are the main purposes of regulatory policies? Check all that apply.
    5·2 answers
  • Ex1. Classify the following statements as business (B), functional (F), non- functional (N), or data (D) requirements; for the l
    13·1 answer
  • What technology has a function of using trusted third-party protocols to issue credentials that are accepted as an authoritative
    12·1 answer
  • Which of the following is used to move to end of the row?​
    8·1 answer
  • When you start a new blank document, you begin typing at the
    6·1 answer
  • Insert XXX to output the student's ID. public class Student { private double myGPA; private int myID; public getID) { return myI
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!