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
What is the difference between connecting link and missing link ?
JulijaS [17]
It's simple. Missing link is the connecting link which had been cut or extinct. The main example are extinct animal species.
8 0
3 years ago
What is the difference between asking a question with few points and asking a question with many? New to Brainly :D
ANTONII [103]

Answer:

one would be more helpful and the other more vague and less convincing.

6 0
3 years ago
Write an application that solicits and inputs three integers from the user and then displays the sum, average, product, smallest
Oksana_A [137]

Answer:

Please find below program

Explanation:

import java.util.Scanner;

public class Tester {

public static void main(String[] args) {

 

 // create an object of scanner class

 Scanner scanner  = new Scanner(System.in);

 

 //prompt user to enter first number

 System.out.println("Enter first integer: ");

 

 // read value from entered by user and keep it in num1

 int num1 = scanner.nextInt();

 

 //prompt user to enter second number

 System.out.println("Enter second integer: ");

 

 // read value from entered by user and keep it in num2

 int num2 = scanner.nextInt();

 

 //prompt user to enter third number

 System.out.println("Enter third integer: ");

 

 // read value from entered by user and keep it in num3

 int num3 = scanner.nextInt();

 //close scanner as we have done with user input

 scanner.close();

 

 //calculate sum

 int sum = num1+num2+num3;

 

 //calculate average

 int average = sum/3;

 

 //calculate product

 int product = num1*num2*num3;

 

 //find out largest number

 int largest = 0;

 if (num1>=num2){

  if(num1>=num3)

   largest = num1;

  else

   largest = num3;

 }else {

  if(num2>=num3)

   largest = num2;

  else

   largest = num3;

 }

 

 // find out smallest number

 int smallest = 0;

 if (num1<=num2){

  if(num1<=num3)

   smallest = num1;

  else

   smallest = num3;

 }else {

  if(num2<=num3)

   smallest = num2;

  else

   smallest = num3;

 }

 

 // print all the information

 System.out.println("Sum of three numbers : "+sum);

 System.out.println("Product of three numbers : "+product);

 System.out.println("Average of three numbers : "+average);

 System.out.println("Smallest number : "+smallest);

 System.out.println("Largest number : "+largest);

}

}

3 0
4 years ago
A technician would like to have the ability to add physical hard drives to a Storage Spaces storage pool at future times on an a
zavuch27 [327]

Answer:

b. Thin provisioning

Explanation:

Thin provisioning is a storage space feature that makes allocating disk storage space flexible based on the space needed by each user, it improves the way storage space is utilized.

4 0
3 years ago
I just need the flowchart and pseudocode.No need program.
nevsk [136]

The pseudocode algorithm for the given program is:

  1. PROCESS saving account transactions
  2. REQUEST for previous account balance
  3. FOR every deposit made, (+)
  4. FOR every withdrawal made (-)

<h3>What is a Pseudocode?</h3>

This refers to the use of plain language to describe the sequence of steps for solving a problem in human language.

Hence, we can see that the complete step is given below:

5. DISPLAY "Withdrawal" when (-) is used.

6. DISPLAY "Deposit" when (+) is used

7. ELSE

8. PRINT "Error"

#SPJ1

Read more about flowcharts and pseudocodes here:

brainly.com/question/24735155

3 0
2 years ago
Other questions:
  • What attributes a website indicates a more reliable source for information
    14·1 answer
  • Task manager is showing an application as “not responding.” what can you do?
    11·1 answer
  • Upon combustion a .8009 g sample of a compound containing only carbon hydrogen and oxygen produced 1.6004 g of CO2 and .6551 g o
    10·1 answer
  • Electricity was seen as a mysterious force and began to creat a stir when people called​
    13·1 answer
  • What type of hardward drive not require defragging??
    11·1 answer
  • How can a Word user insert a page break into a document to isolate a table on a new page?
    13·2 answers
  • Which BEST identifies the primary function of the key words above?
    5·1 answer
  • What qualities in an employee are highly desired by employers?
    6·2 answers
  • What is text formatting/
    5·1 answer
  • A(n) ________ is a way of retrieving information from one or more tables that defines a particular subset of data.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!