I am currently working on writing a simple vending machine that dispenses just one drink, I am just a beginner at this so I would appreciate some help from this community.
package assignment1;
public class VendingMachine
extends java.lang.Object{
// fields
java.lang.String givenDrinkName;
private int givenDrinkPrice;
private static final int INITIAL_BALANCE = 0;
private int balance;
// constructors
public VendingMachine() {
givenDrinkName = "juicy";
balance = INITIAL_BALANCE;
}
public void insertCoin(int amount) {
balance = amount;
}
public int getBalance () {
return balance;
}
public int makeChange() {
int change = balance;
balance = 0;
return balance;
}
public java.lang.String dispense() {
return givenDrinkName;
}
}
Now I know I need a main method (possibly public static void main(String[] args)) but where does this go? and will my script work? The vending machine is supposed to dispense a drink, tell you the balance, make change, and be able to insert the amount to purchase the drink. I don't believe this script has to be that specific but I am wondering if this script works