Question
java: LO: (Apply) Students will write conditional code that implements written requirements. LO: (Apply) Students will validate parameters to a function. Write the body of
java:
LO: (Apply) Students will write conditional code that implements written requirements.
LO: (Apply) Students will validate parameters to a function.
Write the body of a function that operates a vending machine according to the problem description and its docstring.
- This vending machine has nine buttons on its keypad, from 1 to 9.
- The top row of the keypad is 7, 8, 9.
- Items in the top row of the keypad cost $1.50, all other items cost $1.25.
- When the customer arrives, item 6 is out of stock, all other items have five in stock.
- The customer must press a valid keypad button, pay enough money, and have enough items left in order to get something from the vending machine.
- Print the message "Selected a valid item." or "Selected an invalid item." depending on whether the customer selected a valid item number.
- If the customer selected a valid item number, print the message "Payment was enough." or "Payment was not enough." depending on whether the customer paid enough money for the item.
- Print the message "Here is your item." or "You get nothing." depending on whether the customer ultimately gets the item they wanted.
starter code:
public class VendingMachine {
/** * Operates the vending machine and displays messages based on the outcomes. * @param keypad: the number entered by the customer on the keypad * @param payment: the amount of money in dollars the customer paid */ public static void vend(int keypad, double payment) {
}
}
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