hey I'm writing a console app in java that is a vending machine. I have to have 2 vend() methods and a insertMoney() method. Right now I only have a insertMoney() method and I'm having a problem calling it. The error I get is that when it runs through I can't get the variable 'credit' to update with the amount entered from the user.
package javaapplication3;
import java.util.Scanner;
public class CandyMachine {
Scanner getinput = new Scanner(System.in);
//variables for money
static int quarters;
static int dollars;
static int dimes;
static int nickels;
public static int credit;
//variables for stock of candy
static int twix = 10;
static int snickers = 5;
static int skittles = 8;
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
while (true) {
System.out.println("*******************************************");
System.out.println("Vending options are as follows...");
System.out.println("0: Enter Money: ");
System.out.println("1: twix 2.00 dollars");
System.out.println("2 snickers 1.00 dollars");
System.out.println("3 skittles 2.50 dollars");
System.out.println("4 Return Change");
System.out.println("*********************************************");
int userSelection = input.nextInt();
switch (userSelection) {
case 0:
insertMoney();
break;
case 1:
System.out.println("Enter 2.00 dollars please");
if (credit >= 200) {
twix -= 1;
} else {
System.out.println("Enter more money");
}
break;
case 2:
System.out.println("Eneter 1.00 dollar please");
if (credit >= 200) {
snickers -= 1;
} else {
System.out.println("Enter more money");
}
break;
case 3:
System.out.println("Enter 2.50 dollars please");
if (credit >= 250) {
skittles -= 1;
} else {
System.out.println("Enter more money");
}
break;
case 4:
if (credit > 0) {
System.out.println("Hack me for your money back :) ");
}
break;
default:
System.out.println("Please enter a correct number you anarchist.");
break;
}
}
}
public static void insertMoney() {
int moneySelection;
Scanner getinput = new Scanner(System.in);
do {
System.out.println("1: Enter quarters");
System.out.println("2: Enter dimes");
System.out.println("3: Enter nickels");
System.out.println("4: Enter Dollars");
System.out.println("5: When all money is entered");
moneySelection = getinput.nextInt();
switch (moneySelection) {
case 1:
System.out.println("How many quarters? ");
int userQuarters = getinput.nextInt();
credit = quarters * 25;
//break;
case 2:
System.out.println("How many dimes?");
int userdimes = getinput.nextInt();
credit = dimes * 10;
//break;
case 3:
System.out.println("How many Nickels?");
int userNickels = getinput.nextInt();
credit = nickels * 5;
//break;
case 4:
System.out.println("How many Dollars?");
int userDollar = getinput.nextInt();
credit = credit * 100;
//break;
case 5:
System.out.println("Thank you");
break;
}
//return credit;
} while (moneySelection != 5);
}
}