public class VendingMachineController
extends java.util.Observable
Constructor and Description |
---|
VendingMachineController()
Create a vending machine controller with 10 bananas and 10 apples as contents.
|
VendingMachineController(int bananas,
int apples)
Constructs a new vending machine controller with a specific amount
of bananas and apples.
|
Modifier and Type | Method and Description |
---|---|
void |
cancel()
Cancels the buying of a fruit.
|
int |
getCurrentMoney()
Returns the amount of money that was entered after the last fruit was dispensed.
|
Fruit |
getDispensedItem()
Returns the fruit that was last dispensed.
|
int |
getNumberOfFruit(Fruit fruit)
Returns the number of fruits of type fruit left that can be sold.
|
int |
getPrice(Fruit fruit)
Returns the price of a fruit
|
int |
getRest()
Returns the value of any over payments from the last time a fruit was dispensed.
|
int |
getTotalMoney()
Returns the amount of money corresponding to how many fruit was sold.
|
boolean |
hasFruit(Fruit fruit) |
void |
input(int amount)
Simulates putting coins into the machine.
|
Fruit |
selectedFruit()
Returns the selected fruit.
|
void |
selectFruit(Fruit fruit)
Selects a fruit that is dispensed by the vending machine given that there is enough
money entered to pay for the fruit and that the fruit is available.
|
public VendingMachineController()
public VendingMachineController(int bananas, int apples)
bananas
- the number of bananasapples
- the number of applespublic int getNumberOfFruit(Fruit fruit)
fruit
- public void input(int amount)
amount
- the amount of money entered in the machine.public void selectFruit(Fruit fruit)
fruit
- public void cancel()
public int getCurrentMoney()
public int getTotalMoney()
public int getRest()
public Fruit selectedFruit()
public Fruit getDispensedItem()
public int getPrice(Fruit fruit)
fruit
- public boolean hasFruit(Fruit fruit)