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.
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) {
}
}
Test Case 1

Debugging Information for Test Case 1 0 X DEBUG INFO Your instructor has chosen to give you the following information to help you debug your code and improve your submission. COMPILER STACK TRACE None PROGRAM EXECUTION STACK TRACE None INPUT OF THE TEST CASE 1 4 2 1.25 YOUR CODE'S OUTPUT 1 Customer pressed 4 on the keypad. Customer paid $1.25 to the machine. WN THE CORRECT OUTPUT OF THE TEST CASE WN 1 Customer pressed 4 on the keypad. 2 Customer paid $1.25 to the machine. 3 Selected a valid item. 4 Payment was enough. Here is your item. 6 UNIX DIFF OF CORRECT OUTPUT AND YOUR OUTPUT 2a3,5 > Selected a valid item. > Payment was enough. > Here is your item. PRETTY DIFF This diff is colored to make it clear what parts of the output are wrong. Green indicates things in the correct output that you are missing, things in your output that shouldn't be there. indicates The character refers to newlines, so the green character refers a newline you are missing in your output and the red refers to a newline you need to remove from your output. 1 Customer pressed 4 on the keypad. Customer paid $1.25 to the machine. Selected a valid item. Payment was enough. Here is your item. 4 5 6
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
