Question: Write a Java program that modifies and improves Programming Assignment 1 a . This version should disallow zero quantity orders ( management has decided that

Write a Java program that modifies and improves Programming Assignment 1a. This version
should disallow zero quantity orders (management has decided that everyone must buy at least
one sandwich and at least one beverage for supply cost reasons).
- Assume the convenience store only sells two items: beverages at $0.50 each and sandwiches
at $2.75 each. Prices can be hard-coded, but should be set/stored in variables, and those
variables should be used in all calculations.
- Prompt the user for the number of beverages and store the entered quantity as a decimal
number.
o If the quantity is positive, display the quantity and which item was ordered. If a positive
quantity is entered, output product and quantity. If the user enters a zero, display an
error message and ask the user, only once, for another quantity for that item.
- Prompt the user for the number of sandwiches and store the entered quantity.
o If a positive quantity is entered, output the product and quantity. If the user enters a
zero, display an error message and ask the user, only once, for another quantity for that
item.
- Only display the order total if the number of sandwiches is greater than zero and the number of
beverages is greater than zero. This should be executed with a nested-if statement or using
logical operators.
2
- If both of those conditions are not met, display a message saying that management requires at
least one of each item being ordered. If they are met, display the subtotal, then the total with a
7.5% sales tax added (do not worry about any extra decimals for now, as ugly as it will be).
HINTS/NOTES
Drawing a flowchart for the required behavior of this program will help you identify what types
of conditional statements to use, and when to use those statements. Pay attention to the
sample runs provided in the expected output and how they operate.
Depending on the tax calculation used, a differing number of decimal places may appear in
output. The method used for the expected output calculates percentage increase/decrease as a
multiplication times 1.X with X being the percentage (so something like tot = sub *1.15 for
15% as opposed to tot = sub +(sub *.15)).
If you are not using that style, it is likely going to involve differing decimal places. The other test
cases will not execute if any fail, so you should use the above tax calculation method.
Do not try to oversimply output in this problem. There will be times you may need to repeat
code to make this assignment work as shown.
3
There are multiple test cases that your code should pass if it handles everything correctly.
There are cases which produce a valid order, and cases that should produce error(s). For
simplicity, the inputs are grouped together in the Expected Output sections below:
Expected Output, valid input (do NOT hard code your output):
Input: 53(shown), or 053, or 503
Enter the number of beverages: 5
Ordered: 5.0 beverages
Enter the number of sandwiches: 3
Ordered: 3.0 sandwiches
The subtotal of 5.0 beverages and 3.0 sandwiches is $10.75.
With tax, the total is $11.55625.
=================== DIFFERENT TEST RUN BELOW =======================
Input: 53, or 053(shown), or 503
Enter the number of beverages: 0
ERROR: A quantity of zero is not allowed.
Enter the number of beverages: 5
Ordered: 5.0 beverages
Enter the number of sandwiches: 3
Ordered: 3.0 sandwiches
The subtotal of 5.0 beverages and 3.0 sandwiches is $10.75.
With tax, the total is $11.55625.
=================== DIFFERENT TEST RUN BELOW =======================
Expected Output, invalid input (do NOT hard code your output):
Input: 003(shown), or 500, or 0000
Enter the number of beverages: 0
ERROR: A quantity of zero is not allowed.
Enter the number of beverages: 0
Ordered: 0.0 beverages
Enter the number of sandwiches: 3
Ordered: 3.0 sandwiches
Your order total could not be calculated due to a zero quantity for an item

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!