我确定我缺少一些简单的东西,但我无法让我的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