Starting from:

$30

Lab 04: Generic Cheese Shop v2

Lab 04: Generic Cheese Shop v2
CSE-021-01

Overview
We will gain some hands-on experience with methods in this lab.
Getting Started
After starting Eclipse, create a new project called Lab21_4. Import GenCheeseShopv2.java from the
assignment page.
To get some idea of what needs to be done, examine the slides from lecture 03. You will see a method called
getSampleSize(input) in slide 4. This method implements the first process (labelled “A” in slide 3),
where we print a prompt to the user and get the sample size. Similarly, we can create a method that prints
the names and prices of all cheeses sold, while populating the names and prices arrays, and initializing the
amounts array. This new method is declared in the following way:
public static void intro(String[] names, double[]prices, double[] amounts)
The method intro gets three arguments: pointer to names array, pointer to prices array and pointer to
amounts array. They are of types String, double and int respectively. We can invoke the method by
calling it like this:
intro(names, prices, amounts);
Another method called getAmount is used to get the amounts of each type of cheese. Instead of calling
getAmount for each type of cheese, we can create a method which will obtain order amounts for all cheeses
at once. We use the following declaration of getAmount using three parameters:
public static void getAmount(Scanner sc, String[] names, double[] amounts)
Note that this method does not return anything, but just fills the amounts array.
Part 1: Fix GenCheeseShopv2.java
Only fill-in the parts as indicated in GenCheeseShopv2.java. The expectation is you know what code
belongs in these methods that are called by main by matching the specification to the names of the methods.
Some code will be similar to Lab 03 with some minor changes. Think about how to tell how many cheeses
there are based on the arrays passed into each method without needing the variable MAXCHEESE to
control the loops. Do NOT change main or the method declarations. Fix the code where it indicates to fix
(right now it is always returning just 0). The program will compile and run as given but obviously it is not
doing much.
Your program will do the following:
A. List all the cheese types available and the prices
B. Asks the user how many pounds of each type of cheese to purchase in 0.5 lb increments.
C. Calculate Original Sub Total (price*amount of each cheese added together)
D.Calculate discounts based on how many pounds for Humboldt Fog and Red Hawk cheeses the user
entered, as well as the total purchase amount
o See Discount Calculation details from Lab 03
E. Ask the user if they would like to see a list of what they purchased
o If yes, a list comes up showing how much of each type of cheese they bought and the cost of each
cheese
Lab 04: Generic Cheese Shop v2
CSE-021-01 Points: 20
o If no items are purchased, then display a message stating the same (see the Sample Run 8)
o If the user answers no, then no itemized information is displayed
F. Display Original Sub Total, Specials and New Sub Total, Additional Discount and Final Total as shown
in the Sample Runs below (see Discount Calculation from Lab 03 to see how these are calculated).
Sample Runs (user input shown in green, with each run separated by a dashed line):
-------------------------------------------------------------------------------SAMPLE RUN 1
1 Enter the number of cheeses for shop setup: 0
2
3 We sell 0 kinds of cheese, in 0.5 lb packages.
4
5
6 Original Sub Total: $0.00
7 Specials...
8 None -$0.00
9 New Sub Total: $0.00
10 Additional 0% Discount: -$0.0
11 Final Total: $0.00
-------------------------------------------------------------------------------SAMPLE RUN 2
1 Enter the number of cheeses for shop setup: 1
2
3 We sell 1 kinds of cheese, in 0.5 lb packages.
4 Humboldt Fog: $25.0 per pound
5
6 Enter the amount of Humboldt Fog in lb: 1
7
8 Display the itemized list? (1 for yes) 1
9 1.0 lb of Humboldt Fog @ $25.00 = $25.00
10
11 Original Sub Total: $25.00
12 Specials...
13 Humboldt Fog (Buy 1 Get 1 Free): -$12.50
14 New Sub Total: $12.50
15 Additional 0% Discount: -$0.0
16 Final Total: $12.50
-------------------------------------------------------------------------------SAMPLE RUN 3
1 Enter the number of cheeses for shop setup: 2
2
3 We sell 2 kinds of cheese, in 0.5 lb packages.
4 Humboldt Fog: $25.0 per pound
5 Red Hawk: $40.5 per pound
6
7 Enter the amount of Humboldt Fog in lb: 4.5
8 Enter the amount of Red Hawk in lb: 4.5
9
10 Display the itemized list? (1 for yes) 1
11 4.5 lb of Humboldt Fog @ $25.00 = $112.50
12 4.5 lb of Red Hawk @ $40.50 = $182.25
13
14 Original Sub Total: $294.75
15 Specials...
16 Humboldt Fog (Buy 1 Get 1 Free): -$50.00
17 Red Hawk (Buy 2 Get 1 Free): -$60.75
18 New Sub Total: $184.00
19 Additional 10% Discount: -$18.40
20 Final Total: $165.60
-------------------------------------------------------------------------------SAMPLE RUN 4
1 Enter the number of cheeses for shop setup: 3
2
3 We sell 3 kinds of cheese, in 0.5 lb packages.
4 Humboldt Fog: $25.0 per pound
5 Red Hawk: $40.5 per pound
6 Teleme: $17.25 per pound
7
8 Enter the amount of Humboldt Fog in lb: 0
9 Enter the amount of Red Hawk in lb: 0
10 Enter the amount of Teleme in lb: 0
11
12 Display the itemized list? (1 for yes) 1
13 No items were purchased.
14
15 Original Sub Total: $0.00
16 Specials...
17 None -$0.00
18 New Sub Total: $0.00
19 Additional 0% Discount: -$0.0
20 Final Total: $0.00
-------------------------------------------------------------------------------SAMPLE RUN 5
1 Enter the number of cheeses for shop setup: 4
2
3 We sell 4 kinds of cheese, in 0.5 lb packages.
4 Humboldt Fog: $25.0 per pound
5 Red Hawk: $40.5 per pound
6 Teleme: $17.25 per pound
7 Cheese Type D: $9.15 per pound
8
9 Enter the amount of Humboldt Fog in lb: 2.3
10 Invalid input. Enter a value that's multiple of 0.5: 2.5
11 Enter the amount of Red Hawk in lb: 3.5
12 Enter the amount of Teleme in lb: 0
13 Enter the amount of Cheese Type D in lb: 1.7
14 Invalid input. Enter a value that's multiple of 0.5: 1.3
15 Invalid input. Enter a value that's multiple of 0.5: 1.5
16
17 Display the itemized list? (1 for yes) 1
18 2.5 lb of Humboldt Fog @ $25.00 = $62.50
19 3.5 lb of Red Hawk @ $40.50 = $141.75
20 1.5 lb of Cheese Type D @ $9.15 = $13.73
21
22 Original Sub Total: $217.98
23 Specials...
24 Humboldt Fog (Buy 1 Get 1 Free): -$25.00
25 Red Hawk (Buy 2 Get 1 Free): -$40.50
26 New Sub Total: $152.48
27 Additional 10% Discount: -$15.25
28 Final Total: $137.23
-------------------------------------------------------------------------------SAMPLE RUN 6
1 Enter the number of cheeses for shop setup: 10
2
3 We sell 10 kinds of cheese, in 0.5 lb packages.
4 Humboldt Fog: $25.0 per pound
5 Red Hawk: $40.5 per pound
6 Teleme: $17.25 per pound
7 Cheese Type D: $9.15 per pound
8 Cheese Type E: $2.5 per pound
9 Cheese Type F: $8.74 per pound
10 Cheese Type G: $9.88 per pound
11 Cheese Type H: $2.91 per pound
12 Cheese Type I: $6.66 per pound
13 Cheese Type J: $0.36 per pound
14 Enter the amount of Humboldt Fog in lb: 1
15 Enter the amount of Red Hawk in lb: 2
16 Enter the amount of Teleme in lb: 3
17 Enter the amount of Cheese Type D in lb: 0
18 Enter the amount of Cheese Type E in lb: 0
19 Enter the amount of Cheese Type F in lb: 0.3
20 Invalid input. Enter a value that's multiple of 0.5: 4
21 Enter the amount of Cheese Type G in lb: 5
22 Enter the amount of Cheese Type H in lb: 0
23 Enter the amount of Cheese Type I in lb: 0
24 Enter the amount of Cheese Type J in lb: 6
25
26 Display the itemized list? (1 for yes) 0
27
28 Original Sub Total: $244.27
29 Specials...
30 Humboldt Fog (Buy 1 Get 1 Free): -$12.50
31 Red Hawk (Buy 2 Get 1 Free): -$20.25
32 New Sub Total: $211.52
33 Additional 10% Discount: -$21.15
34 Final Total: $190.37
-------------------------------------------------------------------------------SAMPLE RUN 7
1 Enter the number of cheeses for shop setup: 8
2
3 We sell 8 kinds of cheese, in 0.5 lb packages.
4 Humboldt Fog: $25.0 per pound
5 Red Hawk: $40.5 per pound
6 Teleme: $17.25 per pound
7 Cheese Type D: $9.15 per pound
8 Cheese Type E: $2.5 per pound
9 Cheese Type F: $8.74 per pound
10 Cheese Type G: $9.88 per pound
11 Cheese Type H: $2.91 per pound
12
13 Enter the amount of Humboldt Fog in lb: 4
14 Enter the amount of Red Hawk in lb: 5
15 Enter the amount of Teleme in lb: 0
16 Enter the amount of Cheese Type D in lb: 0
17 Enter the amount of Cheese Type E in lb: 0
18 Enter the amount of Cheese Type F in lb: 3.7
19 Invalid input. Enter a value that's multiple of 0.5: 3.2
20 Invalid input. Enter a value that's multiple of 0.5: 3.5
21 Enter the amount of Cheese Type G in lb: 5.5
22 Enter the amount of Cheese Type H in lb: 0
23
24 Display the itemized list? (1 for yes) 1
25 4.0 lb of Humboldt Fog @ $25.00 = $100.00
26 5.0 lb of Red Hawk @ $40.50 = $202.50
27 3.5 lb of Cheese Type F @ $8.74 = $30.59
28 5.5 lb of Cheese Type G @ $9.88 = $54.34
29
30 Original Sub Total: $387.43
31 Specials...
32 Humboldt Fog (Buy 1 Get 1 Free): -$50.00
33 Red Hawk (Buy 2 Get 1 Free): -$60.75
34 New Sub Total: $276.68
35 Additional 25% Discount: -$69.17
36 Final Total: $207.51
-------------------------------------------------------------------------------SAMPLE RUN 8
1 Enter the number of cheeses for shop setup: 5
2 We sell 5 kinds of cheese, in 0.5 lb packages.
3 Humboldt Fog: $25.0 per pound
4 Red Hawk: $40.5 per pound
5 Teleme: $17.25 per pound
6 Cheese Type D: $9.15 per pound
7 Cheese Type E: $2.5 per pound
8
9 Enter the amount of Humboldt Fog in lb: 0
10 Enter the amount of Red Hawk in lb: 0
11 Enter the amount of Teleme in lb: 0
12 Enter the amount of Cheese Type D in lb: 0
13 Enter the amount of Cheese Type E in lb: 0
14
15 Display the itemized list? (1 for yes) 1
16 No items were purchased.
17
18 Original Sub Total: $0.00
19 Specials...
20 None -$0.00
21 New Sub Total: $0.00
22 Additional 0% Discount: -$0.0
23 Final Total: $0.00
Part 2: (Assessment) Logic Check for GenCheeseShopv2.java
Create a Word document or text file named Part2 that contains answers to the following:
1) What parts did you copy from Lab 02 (A-F)?
2) What parts did you copy from Lab 03 (A-F)?
3) How many parts did you change, or create as new (A-F)?
4) Can changing the declaration of calcSubTotal to the following still work?
i. public static double calcSubTotal(double[] p, int[] a)
ii. public static double calcSubTotal(double[] p, double[] a)
iii. public static double calcSubTotal(double[] a, int[] p)
iv. public static double calcSubTotal(int[] a, double[] p)
v. public static double calcSubTotal(double[] p1, int[] p2);
Specification Compliance
The following are some additional instructions to make sure your project complies with specifications:
1. Your program must produce an output that exactly resembles the Sample Output shown below,
including identical wording of prompts, spacing, input locations, etc.
2. Your program must ensure the following:
a. Your program should not display items that are not bought (amount is 0) when listing them out [cf.
Sample Run 7, Lines 25-28]. If no items are purchased, then a special message is displayed [cf.
Sample Run 4, Line 13].
b. If no discounts are applied, a special message is displayed [cf. Sample Run 4, Line 17].
3. Your program must check for invalid inputs when entering the amounts [cf. Sample Run 5, Lines 9-15].
4. Before you submit, in Eclipse, type CTRL-A (to select everything) followed by a CTRL-I (to fix
indentation) on each of your java programs. In MacOS the corresponding keystrokes are Cmd-A
followed by Cmd-I.
What to hand in
When you are done with this lab assignment, submit all your work through CatCourses.
Before you submit, make sure you have done the following:
• Attached the file named Part2 containing answers to Assessment questions (1 – 5).
• Attached the fixed GenCheeseShopv2.java file.
• Filled in your collaborator’s name (if any) in the “Comments…” text-box at the submission page.
Also, remember to demonstrate your code to the TA or instructor before the end of the grace period.

More products