Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Writing the code in main() : Part 1: Create CheeseShop.java The machine will dispense 3 types of cheese, in half-pound packages. The types of cheese

Writing the code in main() :

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Part 1: Create CheeseShop.java The machine will dispense 3 types of cheese, in half-pound packages. The types of cheese and prices are as follows: Humboldt Fog: $25.00 per pound Red Hawk: $40.50 per pound Teleme: $17.25 per pound Your program will do the following: List all the cheese types available and the prices. Asks the user how many pounds of each type of cheese to purchase in 0.5lb increments. . Validate the input to be >= 0 and to be in 0.5 lb increment for positive amounts. Calculate discounts based on how many pounds for each type of cheese the user entered o Discount for Humboldt Fog is that for each 0.5 lb package the user gets another 0.5 lb package for free. o Discount for Red Hawk is that for every two 0.5 lb packages, the user gets a 0.5 lb package for free. o See Discount Calculation below for details. Calculate Sub Total (price * amount of each cheese added together). Ask the user if they would like to see a list of what they purchased. o If the user answers yes, a list comes up showing how much of each type of cheese they bought and the cost of each cheese. Display only the cheese they actually bought. o If no items are purchased, then display a message stating the same (see Sample Run 6). o If the user answers no, then no itemized information is displayed. Display Sub Total, Discount(s) and Final Total. See Discount Calculation below to see how these are calculated Discount Calculation The Humboldt Fog and Red Hawk cheeses are offered at the following special promotions: Humboldt Fog: Buy 1 package get 1 package free Red Hawk: Buy 2 packages get 1 package free where, each package is 0.5 lb. Depending on how much of Humboldt Fog or Red Hawk chesses are bought, we will remove the cost of the free packages from what the user originally bought when calculating the Final Total. For instance, if the user bought 2 lb of Humboldt Fog (4 packages), then 2 of these packages will be free. And if the user bought 2 lb of Red Hawk (4 packages), then 1 of these packages will be free. You may think of the technique of calculating these discounts as marking every 2-package as free for Humboldt Fog, and marking every 3 package as free for Red Hawk. In the table below, the blue cells indicate the free Humboldt Fog packages in a 4.5 lb order giving you 4 packages (or 2 lb) for free. Similarly, the orange cells indicate the free Red Hawk packages in a 4.5 lb order giving you 3 packages (or 1.5 lb) for free. Humboldt Fog #lb #pkg Red Hawk #1b #pkg 0 0,5 0 0,5 2 1.5 4 2.5 6 3,5 94.5 Thus, the itemized list and discount calculation for a 4.5 lb order of these cheeses will appear as follows: Display the itemized list? (1 for yes) 1 4.5 lb of Humboldt Fog @ $25.00 - $112.50 4.5 lb of Red Hawk @ $40.50 - $182.25 Sub Total: $294.75 Specials... Humboldt Fog (Buy 1 Get 1 Free) : -$50. Red Hawk (Buy 2 Get 1 Free): $60.75 Final Total: $184.00 Notice that the itemized list does not show Teleme cheese (assuming the user did not purchase any), and the discounts are applied on the free packages within the order. Here the values are as follows: Sub Total is the price amount of each cheese added together $50 discount for Humboldt Fog corresponds to the 2 lb (or 4 pkgs) in the order that were free $60.75 discount for Red Hawk corresponds to the 1.5 lb (or 3 pkgs) in the order that were free Final Total = Sub Total - (Humboldt Fog discount + Red Hawk discount) Sample Runs (user input shown in green, with each run separated by a dashed line): We sell 3 kinds of Cheese (in 0.5 lb packages): Humboldt Fog: $25.0 per pound Red Hawk: $40.5 per pound Teleme: $17.25 per pound Enter the amount of Humboldt Fog in lbs: 1 Enter the amount of Red Hawk in lbs: 1 Enter the amount of Teleme in lbs: 1 Lo Display the itemized list? (1 for yes) 1 11 1.2 lb of Humboldt Fog @ $25.0 - $25. L2 1.lb of Red Hawk @ $40.5 - $40.5 13 1.2 lb of Teleme @ $17.25 - $17.25 $82.75 15 Sub total: 16 Discounts... 17 Humboldt Fog (Buy 1 Get 1 Free) : -$12.5 18 Final Total: $70.25 ------SAMPLE RUN 2 We sell 3 kinds of Cheese (in 0.5 lb packages): Humboldt Fog: $25.0 per pound Red Hawk: $40.5 per pound Teleme: $17.25 per pound Enter the amount of Humboldt Fog in lbs: 1.4 Invalid input. Enter a value that's multiple of 0.5: 1 Enter the amount of Red Hawk in lbs: -5 Invalid Input. Enter a value >= @: 2 10 Enter the amount of Teleme in lbs: 3 Display the itemized list? (1 for yes) 1 131.lb of Humboldt Fog @ $25.0 - $25. 2.2 lb of Red Hawk @ $40.5 = $81.0 53.lb of Teleme @ $17.25 - $51.75 $157.75 1 Sub total: Discounts... 18 Humboldt Fog (Buy 1 Get 1 Free): 19 Red Hawk (Buy 2 Get 1 Free): 20 Final Total: $12.5 -$20.25 $125. SAMPLE RUN 3 We sell 3 kinds of Cheese (in 0.5 lb packages): Humboldt Fog: $25.0 per pound Red Hawk: $40.5 per pound Teleme: $17.25 per pound Enter the amount of Humboldt Fog in lbs: 1.4 Invalid input. Enter a value that's multiple of .5: -2 Invalid Input. Enter a value > 0: 3.3 Invalid input. Enter a value that's multiple of 0.5: -5 10 Invalid Input. Enter a value > @: 11 Enter the amount of Red Hawk in lbs: 12 Enter the amount of Teleme in lbs: 2 14 Display the itemized list? (1 for yes) 1 5 2.lb of Teleme @ $17.25 - $34.5 $34.5 1 Sub total: Discounts... 19 None 22 Final Total: -$0. $34.5 -SAMPLE RUN 4 We sell 3 kinds of Cheese (in 0.5 lb packages): Humboldt Fog: $25.0 per pound Red Hawk: $40.5 per pound Teleme: $17.25 per pound Enter the amount of Humboldt Fog in lbs: 8.5 Enter the amount of Red Hawk in lbs: 0.5 Enter the amount of Teleme in lbs: LB Display the itemized list? (1 for yes) 1 11 0.5 lb of Humboldt Fog @ $25.0 - $12.5 12 0.5 lb of Red Hawk @ $40.5 - $20.25 32.75 1 Sub total: 15 Discounts... None Final Total: -$. $32.75 -- -SAMPLE RUN 5 We sell 3 kinds of Cheese (in 0.5 lb packages): Humboldt Fog: $25.0 per pound Red Hawk: $40.5 per pound Teleme: $17.25 per pound Enter the amount of Humboldt Fog in lbs: 1 Enter the amount of Red Hawk in lbs: 1 Enter the amount of Teleme in lbs: 1 1 Display the itemized list? (1 for yes) 12 Sub total: $82.75 13 Discounts... 14 Humboldt Fog (Buy 1 Get 1 Free): -$12.5 15 Final Total: $70.25 ----SAMPLE RUN 6 We sell 3 kinds of Cheese (in 0.5 lb packages): Humboldt Fog: $25.0 per pound Red Hawk: $40.5 per pound Teleme: $17.25 per pound Enter the amount of Humboldt Fog in lbs: 0 Enter the amount of Red Hawk in lbs: 0 Enter the amount of Teleme in lbs: Display the itemized list? (1 for yes) 1 11 No items were purchased. $0.0 13 Sub total: Discounts... 15 None 16 Final Total: -$0.0 $0.0 Part 1: Create CheeseShop.java The machine will dispense 3 types of cheese, in half-pound packages. The types of cheese and prices are as follows: Humboldt Fog: $25.00 per pound Red Hawk: $40.50 per pound Teleme: $17.25 per pound Your program will do the following: List all the cheese types available and the prices. Asks the user how many pounds of each type of cheese to purchase in 0.5lb increments. . Validate the input to be >= 0 and to be in 0.5 lb increment for positive amounts. Calculate discounts based on how many pounds for each type of cheese the user entered o Discount for Humboldt Fog is that for each 0.5 lb package the user gets another 0.5 lb package for free. o Discount for Red Hawk is that for every two 0.5 lb packages, the user gets a 0.5 lb package for free. o See Discount Calculation below for details. Calculate Sub Total (price * amount of each cheese added together). Ask the user if they would like to see a list of what they purchased. o If the user answers yes, a list comes up showing how much of each type of cheese they bought and the cost of each cheese. Display only the cheese they actually bought. o If no items are purchased, then display a message stating the same (see Sample Run 6). o If the user answers no, then no itemized information is displayed. Display Sub Total, Discount(s) and Final Total. See Discount Calculation below to see how these are calculated Discount Calculation The Humboldt Fog and Red Hawk cheeses are offered at the following special promotions: Humboldt Fog: Buy 1 package get 1 package free Red Hawk: Buy 2 packages get 1 package free where, each package is 0.5 lb. Depending on how much of Humboldt Fog or Red Hawk chesses are bought, we will remove the cost of the free packages from what the user originally bought when calculating the Final Total. For instance, if the user bought 2 lb of Humboldt Fog (4 packages), then 2 of these packages will be free. And if the user bought 2 lb of Red Hawk (4 packages), then 1 of these packages will be free. You may think of the technique of calculating these discounts as marking every 2-package as free for Humboldt Fog, and marking every 3 package as free for Red Hawk. In the table below, the blue cells indicate the free Humboldt Fog packages in a 4.5 lb order giving you 4 packages (or 2 lb) for free. Similarly, the orange cells indicate the free Red Hawk packages in a 4.5 lb order giving you 3 packages (or 1.5 lb) for free. Humboldt Fog #lb #pkg Red Hawk #1b #pkg 0 0,5 0 0,5 2 1.5 4 2.5 6 3,5 94.5 Thus, the itemized list and discount calculation for a 4.5 lb order of these cheeses will appear as follows: Display the itemized list? (1 for yes) 1 4.5 lb of Humboldt Fog @ $25.00 - $112.50 4.5 lb of Red Hawk @ $40.50 - $182.25 Sub Total: $294.75 Specials... Humboldt Fog (Buy 1 Get 1 Free) : -$50. Red Hawk (Buy 2 Get 1 Free): $60.75 Final Total: $184.00 Notice that the itemized list does not show Teleme cheese (assuming the user did not purchase any), and the discounts are applied on the free packages within the order. Here the values are as follows: Sub Total is the price amount of each cheese added together $50 discount for Humboldt Fog corresponds to the 2 lb (or 4 pkgs) in the order that were free $60.75 discount for Red Hawk corresponds to the 1.5 lb (or 3 pkgs) in the order that were free Final Total = Sub Total - (Humboldt Fog discount + Red Hawk discount) Sample Runs (user input shown in green, with each run separated by a dashed line): We sell 3 kinds of Cheese (in 0.5 lb packages): Humboldt Fog: $25.0 per pound Red Hawk: $40.5 per pound Teleme: $17.25 per pound Enter the amount of Humboldt Fog in lbs: 1 Enter the amount of Red Hawk in lbs: 1 Enter the amount of Teleme in lbs: 1 Lo Display the itemized list? (1 for yes) 1 11 1.2 lb of Humboldt Fog @ $25.0 - $25. L2 1.lb of Red Hawk @ $40.5 - $40.5 13 1.2 lb of Teleme @ $17.25 - $17.25 $82.75 15 Sub total: 16 Discounts... 17 Humboldt Fog (Buy 1 Get 1 Free) : -$12.5 18 Final Total: $70.25 ------SAMPLE RUN 2 We sell 3 kinds of Cheese (in 0.5 lb packages): Humboldt Fog: $25.0 per pound Red Hawk: $40.5 per pound Teleme: $17.25 per pound Enter the amount of Humboldt Fog in lbs: 1.4 Invalid input. Enter a value that's multiple of 0.5: 1 Enter the amount of Red Hawk in lbs: -5 Invalid Input. Enter a value >= @: 2 10 Enter the amount of Teleme in lbs: 3 Display the itemized list? (1 for yes) 1 131.lb of Humboldt Fog @ $25.0 - $25. 2.2 lb of Red Hawk @ $40.5 = $81.0 53.lb of Teleme @ $17.25 - $51.75 $157.75 1 Sub total: Discounts... 18 Humboldt Fog (Buy 1 Get 1 Free): 19 Red Hawk (Buy 2 Get 1 Free): 20 Final Total: $12.5 -$20.25 $125. SAMPLE RUN 3 We sell 3 kinds of Cheese (in 0.5 lb packages): Humboldt Fog: $25.0 per pound Red Hawk: $40.5 per pound Teleme: $17.25 per pound Enter the amount of Humboldt Fog in lbs: 1.4 Invalid input. Enter a value that's multiple of .5: -2 Invalid Input. Enter a value > 0: 3.3 Invalid input. Enter a value that's multiple of 0.5: -5 10 Invalid Input. Enter a value > @: 11 Enter the amount of Red Hawk in lbs: 12 Enter the amount of Teleme in lbs: 2 14 Display the itemized list? (1 for yes) 1 5 2.lb of Teleme @ $17.25 - $34.5 $34.5 1 Sub total: Discounts... 19 None 22 Final Total: -$0. $34.5 -SAMPLE RUN 4 We sell 3 kinds of Cheese (in 0.5 lb packages): Humboldt Fog: $25.0 per pound Red Hawk: $40.5 per pound Teleme: $17.25 per pound Enter the amount of Humboldt Fog in lbs: 8.5 Enter the amount of Red Hawk in lbs: 0.5 Enter the amount of Teleme in lbs: LB Display the itemized list? (1 for yes) 1 11 0.5 lb of Humboldt Fog @ $25.0 - $12.5 12 0.5 lb of Red Hawk @ $40.5 - $20.25 32.75 1 Sub total: 15 Discounts... None Final Total: -$. $32.75 -- -SAMPLE RUN 5 We sell 3 kinds of Cheese (in 0.5 lb packages): Humboldt Fog: $25.0 per pound Red Hawk: $40.5 per pound Teleme: $17.25 per pound Enter the amount of Humboldt Fog in lbs: 1 Enter the amount of Red Hawk in lbs: 1 Enter the amount of Teleme in lbs: 1 1 Display the itemized list? (1 for yes) 12 Sub total: $82.75 13 Discounts... 14 Humboldt Fog (Buy 1 Get 1 Free): -$12.5 15 Final Total: $70.25 ----SAMPLE RUN 6 We sell 3 kinds of Cheese (in 0.5 lb packages): Humboldt Fog: $25.0 per pound Red Hawk: $40.5 per pound Teleme: $17.25 per pound Enter the amount of Humboldt Fog in lbs: 0 Enter the amount of Red Hawk in lbs: 0 Enter the amount of Teleme in lbs: Display the itemized list? (1 for yes) 1 11 No items were purchased. $0.0 13 Sub total: Discounts... 15 None 16 Final Total: -$0.0 $0.0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Fundamentals Concepts, Drivers & Techniques

Authors: Thomas Erl, Wajid Khattak, Paul Buhler

1st Edition

0134291204, 9780134291208

More Books

Students also viewed these Databases questions

Question

=+c) Which model fits better?

Answered: 1 week ago