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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!