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

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

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!