Question
VendingMachine(itemName: String, itemCount: int, itemPrice: double) VendingMachine() getItemName():String getItemCount(): int getItemPrice():double setItem(newItemName: String, newItemCount: int, newItemPrice: double) getTotalCoinValue(): double getAmountCharged(): double purchase(quarters:int, dimes: int, nickels:
VendingMachine(itemName: String, itemCount: int, itemPrice: double) VendingMachine() getItemName():String getItemCount(): int getItemPrice():double setItem(newItemName: String, newItemCount: int, newItemPrice: double) getTotalCoinValue(): double getAmountCharged(): double purchase(quarters:int, dimes: int, nickels: int) : boolean purchase(cardType: String) : boolean |
Instantiate the following:
pepsiMachine - sells "Pepsi Can", initial count: 30, price: $1.05
chipMachine - sells "Pringles Original", initial count: 20, price: $1.75
Print out the item name, the count and the price.
After each of the following transactions, print out the remaining count of the item in the machine, the monetary value of the coins in the machine, and the total amount charged by credit card at the machine.
The following transactions are made:
purchase attempt at pepsiMachine 4 quarters, 1 dimes, 0 nickels.
purchase attempt at pepsiMachine using Visa card. purchase attempt at pepsiMachine using 2 quarters, 4 dimes, 2 nickels. purchase attempt at chipMachine using 6 quarters, 3 dimes, 0 nickels purchase attempt at chipMachine using Visa card item change at pepsiMachine: "Diet Pepsi can", initial count 5, $1.08 purchase attempt at pepsiMachine using 3 quarters, 4 dimes, 0 nickels. purchase attempt at pepsiMachine using 3 quarters, 4 dimes, 0 nickels. purchase attempt at pepsiMachine using Visa card. purchase attempt at pepsiMachine using Discover card. purchase attempt at pepsiMachine using Mastercard. purchase attempt at pepsiMachine using 3 quarters, 0 dimes, 7 nickels. purchase attempt at pepsiMachine using AMEX
***********************************
VendingMachine class is used to instantiate VendingMachine objects. The vending machine never gives change (extra credit if you make a machine that gives change. Keep it mind that it must have those coins on hand, otherwise, the program needs to check to see if another set of coins can be given).
The vending machine only sells one type of product at a time. The item that is sold can change -- the setItem() method is used to set the itemName, itemCount and itemPrice for the new item. The price of the item should end with a 0 or 5 -- because the machine does not accept pennies. Round the price up to the nearest nickel. Ex: if the price is $1.08, round up to $1.10. If it is $0.72, round up to $0.75, etc. This must cover all cases, not just these two values.
There are two purchase() methods -- purchase() is overloaded:
Purchases can be made using coins: quarters, dimes, nickels. The machine keeps track of the number of quarters, number of dimes and number of nickels. The first purchase() method will take a String itemName, number of quarters, number of dimes, number of nickels. If the number of items in the machine is 0, print "No items remaining." If the value of the coins is less than the price of the item, print "Insufficient amount inserted. Returning coins." If any of the purchase cannot be made, return false. Otherwise, there are items remaining in the machine and the value of the coins inserted is greater than or equal to the price of the item and the purchase can be made: decrement the itemCount, add the coins to the respective field variables, return true.
Purchases can also be made using credit cards: Visa, Mastercard, AMEX. No other cards are accepted. The machine keeps track of total value of purchases made by credit card. The second purchase() method will take a String itemName and a String cardType. It will check if the cardType is accepted (Visa, MasterCard, or AMEX). If it does not match, print "Card not accepted". If the number of items in the machine is 0, print "No items remaining." If the purchase cannot be made, return false. Otherwise the selection is valid, there are enough items remaining and the cardType is accepted, decrement the itemCount, add the value of the item to the amountCharged.
getAmountCharged() will return the total amount charged by credit card getTotalCoinValue() will return the monetary value of the coins in the machine.
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