$30
CS401 Assignment 1
Assignment 1: Java Code Coffee Shop Program
Description
Your assignment is to write a program called JavaCodeCoffeeShop (save it in file named JavaCodeCoffeeShop.java)
that simulates a coffee shop called “Java Code Coffee Shop”.
In your virtual coffee shop, a customer will have the ability to select a drink or a pastry to purchase, along with the
quantity of that item. If the customer selects a drink, then your program should offer him a pastry – and vice versa.
After obtaining the item selection and desired quantity from the customer, your program should calculate the cost,
tax, discount, and final cost, then display these to the customer.
At that point, your program should allow the customer to pay for the order (we will simulate this by prompting the
customer to enter a dollar amount), print the final output, and terminate.
Program Requirements
Your program must run as follows:
a. Prompt the customer for his/her name. Read the customer’s input and store it in your program.
b. Display the following welcome message to the customer, where name is the name entered by the customer:
Welcome to Java Code Coffee Shop, name!
c. Display the menu on the screen, with each item and the item’s cost listed on a numbered line (you do not need to
show the “Type” column - see the sample runs below for an example). Here are the items and the cost of each item:
Item Type Cost
Coffee drink $1.50
Latte drink $3.50
Cappuccino drink $3.25
Espresso drink $2.00
Scone pastry $2.50
Muffin pastry $3.00
d. Prompt the customer to select an item. The customer will select an item by entering the number that corresponds
to the desired item. Read the customer’s input and store it in your program.
e. Prompt the customer to enter the quantity for the selected item. Read the customer’s input and store it in your
program.
2
f. There are 2 cases to handle here:
(1) If the customer selected a drink, then offer a pastry:
Would you like a scone or muffin to go with your [beverage](s)? Enter 1 for “yes” or 0 for “no”?
where [beverage] is the name of the customer’s beverage choice (e.g. coffee).
(2) If the user answers “yes”, then allow the user to choose a pastry and a quantity. If the user answers “no”, then
move on to the next step.
If the customer chose a pastry, then suggest a drink:
Would you like to add a coffee or espresso drink to your order? Enter 1 for “yes” or 0 for “no”?
If the user answers “yes”, allow the user to choose a beverage and a quantity. If the user answers “no”, then move
on to the next step.
g. Calculate the total cost of the order. Orders that have a total that is $10 or more should receive a 10% discount.
If the customer earned a discount, calculate the dollar amount of the discount.
h. Calculate the price-after-discount by subtracting the discount dollar amount from the total.
i. Calculate the tax dollar amount. Apply tax to the price-after-discount. The tax rate is 7%.
j. Calculate the final cost by adding the tax dollar amount to the price-after-discount.
k. Display the total cost (i.e. cost before discount and tax), price-after-discount, tax amount, and final cost to the
customer (see the sample runs below for an example to follow). Format all dollar amounts to two decimal places in
the output. Also, be sure to display each dollar amount with a dollar sign ($).
l. Prompt the user to enter a payment amount. Read this amount and store it in your program.
If the amount entered by the user is less than the total cost, then display the following error message:
I’m sorry, but your payment is insufficient. Please stop by again in the future, name!
Otherwise, display the following message:
Thank you for your purchase, name! Your change is $[change]! Have an awesome day!
where change is the difference between the total cost and the payment (e.g. if the total cost is $18.00 and the
payment is $20.00, then [change] would be: 2.00).
m. Terminate your program.
3
Coding Requirements
1. You must store the price of each item and the tax rate (0.07) in a constant (i.e. a variable initialized with the
keyword final), and you must use the constants in all calculations that involve the price of an item or the tax rate
instead of using the corresponding numeric literals in the calculations.
2. You must include a multi-line comment at the top of your source file that includes your name, the class name
(CS401), the semester (Spring 2018), and the assignment name (Assignment 1), with one of these items per line.
3. You must print each of your calculated dollar amounts (e.g. tax amount) with exactly two decimal places (There is
more than one way to format numbers in output; see sections 3.10 and 3.11 in the textbook).
4. Use good programming style.
Assumption
You may assume that the customer will enter valid inputs; specifically, when prompted to
(a) choose an item from the full menu, assume the customer will enter 1, 2, 3, 4, 5, or 6;
(b) choose an item that is a beverage, assume the customer will enter 1, 2, 3, or 4;
(c) choose an item that is a pastry, assume the customer will enter 5 or 6;
(d) choose a quantity, assume the customer will enter a positive integer;
(e) enter a dollar amount, assume the customer will enter a positive decimal number;
(f) answer a “yes” or “no” question, assume the customer will enter 1 for “yes” and 0 for “no”.
SS
4
Three Example Program Demos
1. (customer input is in bold, red font)
Please enter your name: Dennis
Welcome to Java Code Coffee Shop, Dennis!
Here is our menu:
1. Coffee $1.50
2. Latte $3.50
3. Cappuccino $3.25
4. Espresso $2.00
5. Scone $2.50
6. Muffin $3.00
Please enter the item number: 2
Please enter the quantity: 2
Would you like a scone or muffin to go with your latte(s)? Enter 1 for “yes” or
0 for “no”: 1
Fantastic! Which pastry would you like? 5
And how many? 2
Total before discount and tax is: $12.00
Discount is: $1.20
Price after discount is: $10.80
Tax: $0.76
Total: $11.56
Please enter your payment amount: 12.00
Thank you for your purchase, Dennis! Your change is: $0.44! Have an awesome
day!
5
2. (customer input is in bold, red font)
Please enter your name: Frank
Welcome to Java Code Coffee Shop, Frank!
Here is our menu:
1. Coffee $1.50
2. Latte $3.50
3. Cappuccino $3.25
4. Espresso $2.00
5. Scone $2.50
6. Muffin $3.00
Please enter the item number: 6
Please enter the quantity: 1
Would you like to add a coffee or espresso drink to your order? Enter 1 for
“yes” or 0 for “no”: 1
Ok! Which beverage would you like? 1
And how many? 4
Total before discount and tax is: $9.00
Discount is: $0.00
Price after discount is: $9.00
Tax: $0.63
Total: $9.63
Please enter your payment amount: 5.00
I’m sorry, but your payment is insufficient. Please stop by again in the
future, Frank!
6
3. (customer input is in bold, red font)
Please enter your name: Dee
Welcome to Java Code Coffee Shop, Dee!
Here is our menu:
1. Coffee $1.50
2. Latte $3.50
3. Cappuccino $3.25
4. Espresso $2.00
5. Scone $2.50
6. Muffin $3.00
Please enter the item number: 5
Please enter the quantity: 8
Would you like to add a coffee or espresso drink to your order? Enter 1 for
“yes” or 0 for “no”: 0
Total before discount and tax is: $20.00
Discount is: $2.00
Price after discount is: $18.00
Tax: $1.26
Total: $19.26
Please enter your payment amount: 20.00
Thank you for your purchase, Dee! Your change is: $0.74! Have an awesome day!