Question: In this lab, you will implement a vending machine that holds cans of soda. To buy a can of soda, the customer needs to insert
In this lab, you will implement a vending machine that holds cans of soda. To buy a can of soda, the customer needs to insert a token into the machine. When the token is inserted, a can drops from the machine. The goal is to determine how many cans in the machine at any given time. We need to be able to add cans to the vending machine, and to buy them from it. It would also be useful to get the number of cans that the machine contains. Translate this informal description into Java class with the name (VendingMachine) and method headers. You will have three methods in your class: addCans: increase number of cans by one buy Cans: decrease number of cans by one getNumberOf Cans return the current number of cans Give the names, parameter variables, and return types of the methods. Then implement the three methods. You can use the following as a start of your class: public class VendingMachine {private int numOfCans = 0;//represent the number of cans in the vending machine
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
