I am creating a program that has a ATM class in which there is a cheqings and savings account that can be changed based on what the user inputs in the main method in the starting class. For some reason when the user enters in the amount to deposit/withdraw from their account the math is done but the value is not stored. therefor when I go to display the account balance both accounts are at their starting values.
public class ATM {
private double cheqBal;
private double savingsBal;
private String bankName;
public ATM(double cheq, double savings, String name) {
cheqBal = cheq;
savingsBal = savings;
bankName = name;
}
public double getCheq() {
return cheqBal;
}
public double getSavings() {
return savingsBal;
}
public String getName() {
return bankName;
}
public void setCheq(double cheq) {
cheqBal = cheq;
}
public void setSavings(double savings) {
savingsBal = savings;
}
public void setName(String name) {
bankName = name;
}
public double depositCheq(double cheq) {
if (cheq < 0) {
System.out.println("Sorry you cannot do that!");
} else {
cheqBal += cheq;
}
System.out.println(getCheq());
return cheqBal;
}
There is the ATM class where the methods for depositing/withdrawing money are. I only showed the deposit chequing method.
double savBal = 500;
double cheqBal = 1000;
ATM bank1 = new ATM(cheqBal, savBal, "BMO");
String userChoice = JOptionPane.showInputDialog("1: Deposit Cheqings \n2: Deposit Savings \n"
+ "3: Withdraw Cheqings \n4: Withdraw Savings \n5: Show Balance\n6: Exit");
int choice = Integer.parseInt(userChoice);
if (choice == 1) {
String cheqIn = JOptionPane.showInputDialog("How much would you like to deposit?: ");
bank1.depositCheq(Double.parseDouble(cheqIn));
cheqBal = bank1.getCheq();
} else if (choice == 2) {
String savIn = JOptionPane.showInputDialog("How much would you like to deposit?: ");
bank1.depositSavings(Double.parseDouble(savIn));
savBal = bank1.getSavings();
} else if (choice == 3) {
String cheqOut = JOptionPane.showInputDialog("How much would you like to withdraw?: ");
bank1.withdrawCheq(Double.parseDouble(cheqOut));
cheqBal = bank1.getCheq();
} else if(choice == 4){
String savOut = JOptionPane.showInputDialog("How much would you like to withdraw?: ");
bank1.withdrawSavings(Double.parseDouble(savOut));
savBal = bank1.getSavings();
}else if(choice == 5){
bank1.toString();
}else if(choice == 6){
break;
There is the main method. When i hit 1 to deposit money it does not reiterate the amount I deposited when i hit 5 to show balance. (all of the main method is in a loop so it continues until exit).
Sorry for the large amount of code, hope you guys understand my problem and can help!