Question
CalculatingSales.java This is an exercise in using repetition structures to calculate the meaning of values related to real objects. Since methods have not yet been
CalculatingSales.java
This is an exercise in using repetition structures to calculate the meaning of values related to real objects. Since methods have not yet been covered in detail, you may do the calculations in a class that contains just a main method. The looping structures require the use of sentinel-controlled loops. Care should be taken that dollar-and-cents values are properly and correctly presented.
-
This program is an approximate simulation of an online ordering application. (This program really does not represent how this function might be done on the WWW.) For this simulation, there are five products available. Each product has a number, a name, and a price. The products are:
Product number Product name Price/unit 1 SOAP $2.98 2 SHAMPOO $4.50 3 LOTION $9.98 4 CONDITIONER $4.49 5 MOISTURIZER $6.87 The user should be asked to enter a product (by number), and a quantity.
- If the user requests a negative quantity, the user should be informed that may not be done, and should be allowed to go back and select another product.
- If the user asks for a product that does not exist, the user should be informed that there is no product, and allowed to enter a different request. The user should be allowed to continue ordering products until product number 0 is requested. At that time, the program will produce an invoice, and terminate.
- If the user requests the same product again, the quantity ordered is to be added to the currently ordered quantity of that product.
The program should use one or more switch statements to determine the price and actions for each product requested. (This program could be simplified using arrays, but arrays have not been studied yet, and this is an opportunity to practice with switch statements.)
The invoice, for each item ordered, should show the product number, the name of the product, the price per unit, and the extended price (the unit price multiplied by the number ordered). The invoice should also show the total cost of the order (no tax calculation is added for this program) The format of the invoice produced at the end must be formatted appropriately, and may be similar to the one shown below in this example.
-
Example of Inputs and Outputs for CalculatingSales.java
Here is an example of inputs to and outputs from this program:
Enter a product number from 1 to 5 (or 0 to stop): 8 Enter quantity ordered: 6 No product available with that Id. Please continue. Enter a product number from 1 to 5 (or 0 to stop): 7 Enter quantity ordered: -5 Quantity may not be negative. Please continue. Enter a product number from 1 to 5 (or 0 to stop): 4 Enter quantity ordered: 15 Enter a product number from 1 to 5 (or 0 to stop): 2 Enter quantity ordered: 10 Enter a product number from 1 to 5 (or 0 to stop): 4 Enter quantity ordered: 2 Enter a product number from 1 to 5 (or 0 to stop): 1 Enter quantity ordered: 1 Enter a product number from 1 to 5 (or 0 to stop): 1 Enter quantity ordered: 2 Enter a product number from 1 to 5 (or 0 to stop): 0 | Item |Quantity| Price | Extension | ---------------------------------------------------| 1 | SOAP | 3 | 2.98 | 8.94 | 2 | SHAMPOO | 10 | 4.50 | 45.00 | 4 | CONDITIONER | 17 | 4.49 | 76.33 | ---------------------------------------------------| Total for Order | 130.27 |
Note that in the above, a product number which does not correspond to an actual product is reported as No product available with that Id via a message to the user. If a negative quantity is requested, the user is also informed that this cannot be done.
The final invoice should not show items that were not ordered (think of a real online ordering situation in which there may be 1,000,000 possible products).
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started