Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions