Question
@@@@@@@Payable Interface: Create an interface called Payable Payable will include An enum, PayType, with the values CASH, CARD, PHONE Two methods: getPayType() which takes no
@@@@@@@Payable Interface:
- Create an interface called Payable
- Payable will include
- An enum, PayType, with the values CASH, CARD, PHONE
- Two methods:
- getPayType() which takes no arguments and returns a PayType
- setPayType(PayType) which takes a single PayType argument and returns void
@@@@@Order class will be updated as follows:
- Order class will implement the Payable interface
- Include an additional attribute, payMethond, of type PayType
- Set payMethod to PayType.CASH in the default constructor
- Include two simple methods for getPayType() and setPayType(PayType)
- Add a line to the bottom of the receipt via the toString() method that shows the payment type as shown in the Example Run
DessertShop class will be updated as follows:
- Include an additional attribute, paymentMethond, of type String
- After all items have been added to the order and before printing the receipt:
- Ask the user what form of payment will be used. Use input validation to only accept valid types, as shown in the Example Run.
BIG HINTS for DessertShop updates:
- Use enum.values() to get a list of all possible values in the enum. This is helpful to run through all enum values in a FOR-loop-for(Payable.PayType type : Payable.PayType.values())
- Use enumValue.name() to get a String version of the ENUM value
- if (paymentMethod.equals(type.name()))
- Use a switch statement to switch on the validated user input and set the order PayType
User input underlined:
Updates for this lab are inbold:
1: Candy 2: Cookie 3: Ice Cream 4: Sunday
What would you like to add to the order? (1-4, Enter for done): 2 Enter the type of cookie: Oatmeal Raisin Enter the quantity purchased: 4 Enter the price per dozen: 3.45
1: Candy 2: Cookie 3: Ice Cream 4: Sunday
What would you like to add to the order? (1-4, Enter for done):
What form of payment will be used? (CASH, CARD, PHONE): Dollars
That's not a valid form of payment.
What form of payment will be used? (CASH, CARD, PHONE):Euros
That's not a valid form of payment.
What form of payment will be used? (CASH, CARD, PHONE):CARD
----------------------------------------------Receipt--------------------------------------------- Oatmeal Raisin Cookies (Box) 4 cookies @ $3.45/dozen: $1.15 [Tax: $0.08] Candy Corn (Bag) 1.50 lbs. @ $0.25/lb.: $0.38 [Tax: $0.03] Gummy Bears (Bag) 0.25 lbs. @ $0.35/lb.: $0.09 [Tax: $0.01] Chocolate Chip Cookies (Box) 6 cookies @ $3.99/dozen: $2.00 [Tax: $0.14] Pistachio Ice Cream (Bowl) 2 scoops @ $0.79/scoop: $1.58 [Tax: $0.11] Vanilla Sundae (Boat) 3 scoops of Vanilla ice cream @ $0.69/scoop Hot Fudge topping @ $1.29: $3.36 [Tax: $0.24] Oatmeal Raisin Cookies (Box) 2 cookies @ $3.45/dozen: $0.58 [Tax: $0.04] ---------------------------------------------------------------------------------------------------- Total number of items in order: 7 Order Subtotals: $9.12 [Tax: $0.66]
Order Total: $9.78 --------------------------------------------------------------------------------------------------- Paid for with CARD.
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