我確定我缺少一些簡單的東西,但我無法讓我的while while循環正確執行。我希望它能夠第一次運行並持續到用戶輸入q。它目前執行一次,然後循環備份以詢問要訪問的帳戶,然後什麼都不做。任何幫助或指引我在正確的方向,所以我可以修復它將不勝感激。Do/while循環執行不正確
public class Crawford_Driver
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
double input1;
String accountChoice;
String accountActivity;
RegularAccount regAcct = new RegularAccount(0, .5);
SavingsAccount savAcct = new SavingsAccount(0, .5);
do{
System.out.println("What account would you like to access(regular or savings)?");
accountChoice = keyboard.nextLine();
if(accountChoice.equalsIgnoreCase("regular"))
System.out.println("What action do you wish to perform(deposit, withdraw or monthly process)? ");
accountActivity = keyboard.nextLine();
if (accountActivity.equalsIgnoreCase("deposit"))
{
System.out.println("How much would you like to deposit?");
input1= keyboard.nextDouble();
regAcct.deposit(input1);
System.out.println("Your balance is " + regAcct.getBalance());
}
else if (accountActivity.equalsIgnoreCase("withdraw"))
{
System.out.println("How much would you like to withdraw?");
input1= keyboard.nextDouble();
regAcct.withdraw(input1);
System.out.println("Your balance is "+ regAcct.getBalance());
}
else if (accountActivity.equalsIgnoreCase("monthly process"))
{
regAcct.monthlyProcess();
}
else {
if (accountChoice.equalsIgnoreCase("savings"))
if (accountActivity.equalsIgnoreCase("deposit"))
{
System.out.println("How much would you like to deposit?");
input1= keyboard.nextDouble();
savAcct.deposit(input1);
System.out.println("Your balance is " + savAcct.getBalance());
}
if (accountActivity.equalsIgnoreCase("withdraw"))
System.out.println("How much would you like to withdraw?");
input1= keyboard.nextDouble();
savAcct.withdraw(input1);
System.out.println("Your balance is "+ savAcct.getBalance());
}
}while (!accountChoice.equalsIgnoreCase("Q"));
}
}
我回去,並添加缺少的括號但是現在它遍歷並詢問什麼帳戶訪問,並立即問多少,而無需等待任何用戶輸入存入。 以下是該計劃的輸出: 您想訪問哪個帳戶(常規或儲蓄)? 定期 您希望執行什麼操作(存款,提款或每月處理)? 存款 您要存多少錢? 您的餘額是44.0 您想要訪問哪個帳戶(常規或儲蓄)? 你想存多少錢? –
我突出了我的例子 - 你的花括號應該包裝你想要在特定環境下做的所有事情(即「常規」)。 – Makoto