cmdを使用してJavaを学習し、コンパイルして実行するATMプログラムを作成しています。プログラムはエラーなしでコンパイルされますが、実行時にのみ出力され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);
}
//}
}