我正在制作一个 ATM 程序来学习 java 使用 cmd 来编译和运行它。该程序编译没有错误,但运行时只打印at ATM.(init)(ATM.java:6)
.
任何帮助将不胜感激!
public class ATM
{
Toolbox myToolbox = new Toolbox();
Integer balance;
ATM myATM = new ATM();
public static void main(String[] arg)
{
ATM myATM = new ATM();
myATM.go();
myATM.printBal();
myATM.mainMenu();
}
public void go()
{
System.out.println("Welcome to online ATM banking");
System.out.println("How much do you want in your account?");
//System.out.println("Enter your number");
balance = myToolbox.readIntegerFromCmd();
}
public void printBal()
{
System.out.println("****************************************");
System.out.println(balance);
System.out.println("****************************************");
}
public void mainMenu()
{
Integer selected;
System.out.println("What do you want to do?");
System.out.println("1 : Withdraw");
System.out.println("2 : Deposit");
System.out.println("3 : Inquire");
System.out.println("4 : Quit");
System.out.println("Enter your number");
selected = myToolbox.readIntegerFromCmd();
//{ if statement for mainMenu options
if(selected.equals(1))
{
myATM.withdraw();
}
else if(selected.equals(2))
{
myATM.deposit();
}
else if(selected.equals(3))
{
myATM.inquire();
}
else if(selected.equals(4))
{
myATM.quit();
}
//} if statement end
}
//{ mainMenu methods
public void withdraw()
{
System.out.println("****************************************");
System.out.println("Withdraw");
System.out.println("****************************************");
Integer takeOut;
System.out.println("How much do you want to withdraw?");
takeOut= myToolbox.readIntegerFromCmd();
balance = balance - takeOut;
myATM.printBal();
myATM.mainMenu();
}
public void deposit()
{
System.out.println("****************************************");
System.out.println("Deposit");
System.out.println("****************************************");
Integer putIn;
System.out.println("How much do you want to deposit?");
putIn = myToolbox.readIntegerFromCmd();
balance = balance + putIn;
myATM.printBal();
myATM.mainMenu();
}
public void inquire()
{
System.out.println("****************************************");
System.out.println("Inquire");
System.out.println("****************************************");
//why am I making a method that is already written
myATM.printBal();
myATM.mainMenu();
}
public void quit()
{
System.out.println("****************************************");
System.out.println("Thanks for using the fail ATM");
System.out.println("****************************************");
System.out.println(balance);
System.out.println("****************************************");
System.out.println("Goodbye");
System.out.println("****************************************");
System.exit(0);
}
//}
}