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.

Answers

Answer 1

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.


Related Questions

PLEASE can someone give me some examples of activities I can put on a resume presentation?

I'm a freshman and I didn't really play any sports other than 8th grade volleyball. I really need some examples​

Answers

Answer:

list down extracurriculars (e.x. maybe you attend piano lessons, or you attend an art class during the weekend, or you play football outside of school, etc.)

you can also list any volunteering you do on the side (e.x. maybe you volunteer at your local church or at the local animal shelter), whatever you think counts.

Write a Python program in Python-IDLE(in Script mode), save and upload in the
classroom for the following. 1) To calculate addition, subtraction, multiplication
of any 2 values which you will input while running the program. 2) To input 5
values, calculate total and average of those five values.
Your answer​

Answers

num1 = int(input(“Enter First Number: “)
num2 = int(input(“Enter Second Number: “)
add_num = num1 + num2
sub_num = num1 - num2
mult_num = num1 * num2
div_num = num1 / num2
print(“Results”)
print(“Addition: “ + add_num)
print(“Subtraction: “ + sub_num)
print(“Multiplication: “ + mult_num)
print(“Division: “ + div_num)

Describe how tuples can be useful with loops over lists and dictionaries, and give Python code examples. Create your own code examples.

Your descriptions and examples should include the following: the zip function, the enumerate function, and the items method.

Answers

Answer:

i dont no

Explanation:


Does anyone know this? Can someone please help me? I’ll give brainliest!!

Answers

Answer:

c. HTML tags

Explanation:

Filtering out the details to leave the general characteristics is referred to as_____.

A. refinement

B. decomposition

C. pattern recognition

D. abstraction

Answers

Answer:  

✔️ A. abstraction

Explanation:

Answer:

abstraction is correct

Explanation:

2
Simone builds a simple spinning engine by inserting straws through holes in a plastic cup. She then suspends the cup from a metal pole using string. After Simone pours water into the cup, the water rushes out of the straws in the direction that the straws are pointed and the cup spins, as shown in the picture below.


Which of the following is true about the force acting on the cup and causing it to spin

Answers

Answer: D It is equal in magnitude but opposite in direction to the force pushing the water out of the straws.
Explanation:

Choose the words that make the following sentence true.
Primary memory is

Answers

Answer:

Primary memory is computer memory that is accessed directly by the CPU

Explanation:

Describe, with examples, the way in which a defect in software can cause harm to a person, to the environment, or to a company

Answers

Answer:

Losing jobs. Fire. Destruction of property.

Explanation:

Having a company shut down due to lack of protection and having people testify products unsafe. If software blows up it could cause desturction of property therefore causing the effect of many people losing their jobs.

Consider the following code segment.
System.out.println("W");
System.out.println("X");
System.out.print("Y");
System.out.print("Z");
What is printed as a result of executing the code segment?

Answers

Answer:

W

X

After that an error would print and error

Explanation:

the last two statements are missing "ln"

Which of the following identifies the two reasons why people may not purchase organic produce as often as conventionally grown produce?



the taste and the appearance of the produce


the cost and the convenience of the produce


the convenience and taste of the produce


the appearance and the cost of the produce

look at this question pls help

Answers

Answer:the taste and the appearance of the produce

Explanation:

A user calls to complain that her computer is behaving erratically. Some days it functions correctly, and other days, it crashes frequently. Sometimes, the system won't boot at all. You open the system case and notice the following: Two of the mounting screws are missing from the system hard disk drive. The system uses memory modules from several different manufacturers with mismatched capacities. Several capacitors on the motherboard are bulging and have a brown liquid oozing from them. The chassis fan on the front of the case is oriented to blow air into the system. What should you do

Answers

Answer:

Replace the motherboard.

Explanation:

The motherboard is the core of the computer. If the motherboard is oozing brown stuff, signifying that one of the sectors has been eroded or is about to disrupt, it needs to be replaced before further damage can be made.

The screws in the hard drive can easily be replaced.

As for the memory sticks, they will operate best if they were the same brand and the same memory size and hertz.

I really need help with this. I don’t have that long until I have to turn it in. Please hurry!

Answers

Answer:

a

Explanation:

the answer to the question is A

Consider the training requirements of a space operations specialist. The first step in the training process is obtaining a general equivalency diploma (GED) with 15 college credits or a high school diploma. What is studied during the next step in the training process?


command operations

satellite control

military training

spacecraft control

Answers

Answer:

Command Operations

Explanation:

Space Operation specialist requires special training for aircraft and its operations along with satellite controls. Initially when a graduate joins the training he is required to understand command operations of aircraft. He can then use his skills to learn command operation of spacecraft and then will be promoted to learn satellite controls.

Answer:

Command Operations

Explanation:

Specialized training for aircraft and their operations, as well as satellite controls, is required for Space Operation Specialists. When a graduate first begins training, he is expected to comprehend aircraft command operations. He can then use his expertise to master spacecraft command operations before being promoted to satellite control.

What is this passage mostly
about?
Working together can help people
tackle difficult problems.
Giving a speech to the United Nations
can be challenging.
Learning about climate change begins
in school.
Collecting information can help set
new goals.

Answers

Answer:

working together can help people tackle difficult problems.

Explanation:

I did the Iready quiz.

what is common for all machines​

Answers

Answer:

the question is a bit vague, but all machines exist to serve a purpose, or to do or accomplish a certain task.

They all need a source of power too

What is a good starting point for data mining?

A. Data Visualization
B. Writing a Data dictionary
C. Non Parametric methods
D. creating a relational database
E. machine learning

Answers

Answer:

A is the answer

Explanation:

hope this help

It is a good starting point for data mining and that is A. Data Visualization.

What is the distinction among data mining and data visualization?

Data Mining is a collection of various sports to extract special styles out of the massive facts units wherein facts units may be retrieved from special facts reassets while Data Visualization is a manner of changing numerical facts into graphical pics like significant 3-D images on the way to be used to analyData Mining data.

Data Visualization. Data mining is a manner of extracting beneficial information, styles, and developments from uncooked facts. Data Visualization refers back to the visible illustration of facts with the assist of complete charts, pics, lists, charts, and different visible objects. It comes below facts science.

Read more about the Data Visualization:

https://brainly.com/question/1822923

#SPJ2

the dash area is used for typing and editing the text​

Answers

Explanation:

document area is used for typing and editing the text

Which stage of the systems development life cycle may involve creating flowcharts to communicate how the program should work?​

Answers

Explanation:

There are usually six stages in this cycle: requirement analysis, design, development and testing,implementation, documentation, and evaluation. It is important to develop a plan of action to reduce delays and meet deadlines.

Systems development life cycle phases include planning, system analysis, system design, development, implementation, integration and testing, and operations and maintenance.

System flowcharts are a way of displaying how data flows in a system and how decisions are made to control events. To illustrate this, symbols are used. ... Data flow charts do not include decisions, they just show the path that data takes, where it is held, processed, and then output .

Write a Java program that will do the following:
Prompt the user for an integer value.
Compute the following information about the number and provide output similar to the examples below.
Is the number even or odd?
Is the number positive, negative, or neither?
Is the number evenly divisible by 5? If not, display nothing.
Is the number evenly divisible by 7? If not, display nothing.
Is the number evenly divisible by 10? If not, display nothing.

Answers

Answer:

I don't know I'm sorry I will tell you another answer asks me to

A school is creating class schedules for its students. The students submit their requested courses and then a program will be designed to find the optimal schedule for all students. The school has determined that finding the absolute best schedule cannot be solved in a reasonable time. Instead they have decided to use a simpler algorithm that produces a good but non-optimal schedule in a more reasonable amount of time. Which principle does this decision best demonstrate

Answers

Answer:

Heuristics

Explanation:

The principle that this kind of decision demonstrate is Heuristics , this is because Heuristics can be used to solve problems when there is no known algorithm to resolve the problem.

Heuristics is a simple algorithm that can provide a good but not optimal solution in the shortest possible time i.e. a shortcut to solutions

Answer:

a

Explanation:

 

7.3.4: Find the Error

Answers

Answer:

my_string = "hello!"

# One of the two lines below will cause an error.

# Each line is an attempt to replace the first

# letter of myString with H. Comment out the

# line you think is incorrect.

# my_string[0] = "H"

my_string = "H" + my_string[1:]

print(my_string)

Explanation:

The numeric or alphanumeric error code is being used to identify the type of error. Following are the description of the error code in the given question:

Incorrect code:

my_string[0] = "H" // this line give the error that is "'str' object does not support item assignment".

Correct code:

my_string = "hello!"#defining the string variable that is "my_string"

my_string = "H" + my_string[1:]#using string variable that perform slicing and hold its value

print(my_string)#print my_string value

Code Explanation:

Defining the string variable that is "my_string".In the next line, the string variable is used that adds "H" to the first index value and performs slicing, and holds its value. Using the print method that prints the "my_string" variable value.

Output:

Please find the attached file.

Find out more about the error here:

brainly.com/question/13106116

What are storage devices ​

Answers

Answer:

=>. storage devices are those devices that is used to store some data in it

It is very important device that gives a lot of benefits in our daily lives

we can also carry our data from one place to another

Well they are pretty much what store files and such on your computer or other device some different types are ssd and hdd

Correct all the mistakes in the following sentence:

When you proofread look for punctuation spelling and Capitalization Mistakes.

Answers

Answer:

When you proofread, look for punctuation, spelling, and capitalization mistakes.

Explanation:

Answer:

When you proofread, look for punctuation, spelling, and capitalization mistakes.

:]

(01.01 LC)
Programmers perform which of the following tasks?
Build and maintain network connections
O Create web and mobile applications
O Design graphics for websites
Repair computers and servers

Answers

Answer:

Create web and mobile applacations

Explanation:

Programmers primarily build and maintain software applications, including web and mobile applications.

What is software?

Programmers typically work with software, which is a collection of instructions and programmes that instruct a computer or other electronic device on what to do.

They create, test, and maintain software applications for desktops, mobile devices, and the web using programming languages such as Java, Python, and C++.

Programmers create and maintain software applications, such as web and mobile applications.

They may also design the application's user interface and user experience, but they are not typically in charge of designing graphics for websites.

Furthermore, while programmers may be involved in troubleshooting and resolving issues related to the software application they have created, they are not typically in charge of repairing hardware such as computers and servers.

Thus, the correct answer is "Build and maintain network connections".

For more details regarding software, visit:

https://brainly.com/question/985406

#SPJ2

The web lab consists of which elements. Select all that apply. Group of answer choices Files Inspector Tool Preview Hints Work Space Instructions

Answers

Answer:

Inspector Tool

Preview

Work Space

Instructions

Explanation:

Web Lab is a function that incorporates HTML in web development. It has functions such as Workspace where the developer writes the body of the website. Preview helps the developer take a look at the final product of what he is creating. Instructions panel provides a list of the different types of html packages that the developer can chose from.

All of these options help the developer produce a website that is up to standard.

Hello my name is Phoenix I will like for you to friend me on Ro blox my user name is Jessiahcoleman and if u play BLOX fruits or something ill help u

Answers

Answer:

Free Points?

Explanation:

and my name is TSM_Holden23 if u ever want to play with me on ps4

Answer: ?

Explanation:

what is the best definition of inflation?

Answers

I mean there’s 2 definitions for it

Inflation is a situation of rising prices in the economy. A more exact definition of inflation is a sustained increase in the general price level in an economy. Inflation means an increase in the cost of living as the price of goods and services rise.


Or inflation can be growing the size (blowing up a balloon)

Which Internet connection type tends to use shared bandwidth?
Cable
Dial-up
DSL
ISDN

Answers

Answer:

try dial-up

Explanation:

Answer:

dial up

Explanation:

what are the two main parts to a VR experience.

Answers

Answer:

The 2 main parts to a VR experience is getting comfortable and interacting with people in the VR if you have friends :3

Explanation:

:3

A good technical writer will make one document for all audiences, no matter what age or ability. True or False? (I’ll give the crown)

Answers

Answer:

It is True

Explanation:

A writer wants to make there readers happy so they can get rich so..... I think it is true.

they brats so times.

Hope this helps

Other Questions
1. What happened to Europe during WWI, and what did the people of Germany and Italy do?2. What happened to the German economy after WWI? Why?(Answer 1 or 2 or both) Plz help, asap, do not paste link for other website.Which of the following points is on the graph of a proportional relationship y=4x-5A (1-2B (7, 3)C (-2, 13)D (2, 3) What is the main way a representative democracy differs from a direct democracy?O Citizens elect leaders who vote on the issues in a representative democracy, and citizens vote on the issues in adirect democracy.O A representative democracy is modern, and a direct democracy is ancient.A representative democracy works better in small groups, and a direct democracy works better in large groups.O Citizens' desires are ignored in a representative democracy, and citizens' desires have a better chance of beingheard in a direct democracy. A pendulum has a mass of 0.060 kg swinging at a small angle from a light string, with a period of 1.4 s. What is the length of the pendulum? please help me on this one Select the correct answer: Which is the best example of a topic that is too broad? .Research shows processed foods can be unhealthy. B.Consuming processed foods has a negative effect on people's health over time. C.Consuming processed foods can affect people's moods.D.Processed foods cause health issues for people with weak immune systems. Who's your celeb crush? Mine is Leonardo Dicaprio, Jake from state farm (ik hes not a celeb but im talking about the black Jake from state farm not the old one. I'm sorry but he got some serious ABS- o-o), Zak Bagans (hes from my favorite ghost hunting tv show "Ghost adventures" from the Travel Channel). (I have more but I forgot them o-o) The length of WV is : 5If x = 4, what is the value of x(14 - x)?OA40OB4416Math A parallelogram has an area of 108 in. the best of the parallelogram is 18 inches find the height. How are infrared waves and radio waves similar? How might you use each? find y for -4 + 3y = 8 please help asap Plss help i need help i beg you!!!! Please help if not thats fine :/ The line plots below show the number of students in each of Andres and Mandys classes at school. Approximately how many times larger is the difference between the means of the number of students in Andres and Mandys classes compared to the range? Which of the following connects an anther to the flower?stylestigmafilamentpistil WILL GIVE BRAINLIEST!!! NO UNHELPFUL ANSWERS OR I WILL REPORT!!! HELP DUE IN 20 MINS! Leave answers as simplified fractions if necessary.m =?? HELLPPPPPPPPPPP PLEAEE!!!!!!!!! If each quadrilateral below is a trapezoid, find the missing measures. #1