So I'm working on this program for a school project and I have to create an ATM. For some reason, entering W in the program below doesn't do anything but R works as intended. I've tried having an Else If and putting the "R" code above the "W" code but nothing seems to work. Sorry for the long piece of code, thanks.
import java.util.ArrayList;
public class ConsutingProblem {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int totalCash;
String choice;
String rrr = "R";
String www = "W";
String iii = "I";
String qqq = "Q";
boolean stopAtm = false;
int hundred = 10;
int fifty = 10;
int twenty = 10;
int ten = 10;
int five = 10;
int one = 10;
totalCash = (hundred*100) + (fifty*50) + (twenty*20) + (ten*10) + (five*5) + one;
do {
System.out.println("Please enter the letter corresponding to your chosen action.");
System.out.println("R for a restock.");
System.out.println("W for withdrawl followed by amount. Example: W $145");
System.out.println("I for number of bills present with that denomination. Example: I $20");
System.out.println("Q for quitting this aplication.");
choice = input.nextLine();
if ((choice.substring(0, 0)).equals(www)) {
int withdrawlAmount = Integer.parseInt(choice.substring(3));
totalCash -= withdrawlAmount;
int displayWithdrawl = withdrawlAmount;
int hundredBack = (int)(displayWithdrawl/100);
displayWithdrawl -= (hundredBack*100);
int fiftyBack = (int)(displayWithdrawl/50);
displayWithdrawl -= (fiftyBack*50);
int twentyBack = (int)(displayWithdrawl/20);
displayWithdrawl -= (twentyBack*20);
int tenBack = (int)(displayWithdrawl/10);
displayWithdrawl -= (tenBack*10);
int fiveBack = (int)(displayWithdrawl/5);
displayWithdrawl -= (fiveBack*5);
int oneBack = (int)(displayWithdrawl/1);
displayWithdrawl -= (oneBack*1);
if (withdrawlAmount <= totalCash && hundredBack <= hundred && fiftyBack <= fifty && twentyBack <= twenty && tenBack <= ten && fiveBack <= five && oneBack <= one) {
System.out.println("Success: Dispensed $" + withdrawlAmount);
hundred -= hundredBack;
fifty -= fiftyBack;
twenty -= twentyBack;
ten -= tenBack;
five -= fiveBack;
one -= oneBack;
System.out.println("Machine Balance:");
System.out.println("$100 - " + hundred);
System.out.println("$50 - " + fifty);
System.out.println("$20 - " + twenty);
System.out.println("$10 - " + ten);
System.out.println("$5 - " + five);
System.out.println("$1 - " + one);
} else {
System.out.println("Faliure: insufficient funds");
}
}
if (choice.equals(rrr)) {
hundred = 10;
fifty = 10;
twenty = 10;
ten = 10;
five = 10;
one = 10;
totalCash = (hundred*100) + (fifty*50) + (twenty*20) + (ten*10) + (five*5) + one;
System.out.println("Machine Balance:");
System.out.println("$100 - " + hundred);
System.out.println("$50 - " + fifty);
System.out.println("$20 - " + twenty);
System.out.println("$10 - " + ten);
System.out.println("$5 - " + five);
System.out.println("$1 - " + one);
}
} while (stopAtm == false);
}
}