Java “我的银行”错误消息在任何情况下都会出现,并且不会';不接受用户输入

Java “我的银行”错误消息在任何情况下都会出现,并且不会';不接受用户输入,java,Java,我很难确保选项2的错误消息仅在用户输入的数字大于其银行余额时出现。然而,即使用户输入的金额小于他们的银行余额,它也会出现。再多玩弄它会让我的问题变得更糟,因为用户必须多次输入答案才能得到响应。如果关于这个问题还有一些不清楚的地方,请告诉我。这是我的第一节编程课,我还没有找到自己的解决方案,所以欢迎任何帮助 //Part 2 double balance = 0; BankAccount myBankAccount=new BankAccount(5

我很难确保选项2的错误消息仅在用户输入的数字大于其银行余额时出现。然而,即使用户输入的金额小于他们的银行余额,它也会出现。再多玩弄它会让我的问题变得更糟,因为用户必须多次输入答案才能得到响应。如果关于这个问题还有一些不清楚的地方,请告诉我。这是我的第一节编程课,我还没有找到自己的解决方案,所以欢迎任何帮助

//Part 2
            double balance = 0;
            BankAccount myBankAccount=new BankAccount(500.00);

        myBankAccount.deposit(1000.00);
        System.out.println(myBankAccount.getBalance());
        myBankAccount.withdrawal(600.00);
        System.out.println(myBankAccount.getBalance());

        //Part 3
        Scanner input=new Scanner(System.in);

        int choice;
        System.out.println("Welcome to M&T Bank!");
        System.out.println("Select a Banking Option Below");
        myBankAccount.menu();
        choice=input.nextInt();
        while(choice<4&&choice>0)
        {
            if(choice==1)
            {
                System.out.println("How much will you deposit?");
                myBankAccount.deposit(input.nextDouble());
            }
            else if(choice==2)
            {
                System.out.println("How much will you withdraw?");
                if(input.nextDouble()>balance)
                {
                    while(input.nextDouble()>balance)
                    {
                        System.out.println("Your account has insufficient funds. Your balance is: "+myBankAccount.getBalance());
                        System.out.println("How much will you withdraw?");
                        myBankAccount.withdrawal(input.nextDouble());
                    }
                }
                else
                {
                    myBankAccount.withdrawal(input.nextDouble());
                }
            }
            else if(choice==3)
            {
                System.out.println("Your balance is: "+myBankAccount.getBalance());
            }
            System.out.println("Welcome to M&T Bank!");
            System.out.println("Select a Banking Option Below");
            myBankAccount.menu();
            choice=input.nextInt();
        }
        if(choice==4)
        {
            System.out.println("Thank you! Goodbye.");
        }
//第2部分
双平衡=0;
银行账户myBankAccount=新银行账户(500.00);
我的银行账户。存款(1000.00);
System.out.println(myBankAccount.getBalance());
我的银行账户提款(600.00);
System.out.println(myBankAccount.getBalance());
//第三部分
扫描仪输入=新扫描仪(System.in);
智力选择;
System.out.println(“欢迎来到M&T银行!”);
System.out.println(“选择下面的银行选项”);
myBankAccount.menu();
choice=input.nextInt();
while(选项0)
{
如果(选项==1)
{
System.out.println(“您将存款多少?”);
myBankAccount.deposit(input.nextDouble());
}
else if(选项==2)
{
System.out.println(“您将提取多少?”);
if(input.nextDouble()>balance)
{
while(input.nextDouble()>balance)
{
System.out.println(“您的帐户资金不足。您的余额为:“+myBankAccount.getBalance()”);
System.out.println(“您将提取多少?”);
myBankAccount.drawing(input.nextDouble());
}
}
其他的
{
myBankAccount.drawing(input.nextDouble());
}
}
else if(选项==3)
{
System.out.println(“您的余额为:+myBankAccount.getBalance());
}
System.out.println(“欢迎来到M&T银行!”);
System.out.println(“选择下面的银行选项”);
myBankAccount.menu();
choice=input.nextInt();
}
如果(选项==4)
{
System.out.println(“谢谢!再见”);
}

每次调用
input.nextDouble()
,您都在读取另一个输入。而且,你是在不计余额的情况下提款。另外,
余额
为0。试试这个:

else if (choice == 2) {
    System.out.println("How much will you withdraw?");
    double amount;
    while ((amount = input.nextDouble()) > myBankAccount.getBalance()) {
        System.out.println("Your account has insufficient funds. Your balance is: "+myBankAccount.getBalance());
        System.out.println("How much will you withdraw?");
    }
    myBankAccount.withdrawal(amount);
}
BankAccount myBankAccount=新银行账户(500.00);
我的银行账户。存款(1000.00);
System.out.println(myBankAccount.getBalance());
我的银行账户提款(600.00);
System.out.println(myBankAccount.getBalance());
扫描仪输入=新扫描仪(System.in);
int choice=input.nextInt();
而(选项>4 | |选项<1){
扫描仪输入=新扫描仪(System.in);
int choice=input.nextInt();}
System.out.println(“欢迎来到M&T银行!”);
System.out.println(“选择下面的银行选项”);
myBankAccount.menu();
开关(选择){
案例1:{
System.out.println(“您将存款多少?”);
myBankAccount.deposit(input.nextDouble());}
案例2:{
System.out.println(“您将提取多少?”);
while(input.nextDouble()>myBankAccount.getBalance()){
System.out.println(“您的帐户资金不足”);
System.out.println(“您的余额为:+myBankAccount.getBalance());
System.out.println(“您将提取多少?”);}
myBankAccount.drawing(input.nextDouble());
}
案例3:System.out.println(“您的余额为:+myBankAccount.getBalance());
案例4:System.out.println(“谢谢!再见”);

语言?我们无法读懂您的心思!抱歉,是Java。
    BankAccount myBankAccount = new BankAccount(500.00);

    myBankAccount.deposit(1000.00);
    System.out.println(myBankAccount.getBalance());
    myBankAccount.withdrawal(600.00);
    System.out.println(myBankAccount.getBalance());

    Scanner input=new Scanner(System.in);
    int choice = input.nextInt();

    while (choice > 4 || choice < 1){
    Scanner input=new Scanner(System.in);
    int choice = input.nextInt();}


    System.out.println("Welcome to M&T Bank!");
    System.out.println("Select a Banking Option Below");
    myBankAccount.menu();

    Switch(choice){
    case 1:{
           System.out.println("How much will you deposit?");
           myBankAccount.deposit(input.nextDouble());}

    case 2:{
            System.out.println("How much will you withdraw?");
            while(input.nextDouble() > myBankAccount.getBalance(){
            System.out.println("Your account has insufficient funds.");
            System.out.println("Your balance is: "+myBankAccount.getBalance());
            System.out.println("How much will you withdraw?");}
            myBankAccount.withdrawal(input.nextDouble());
            }

    case 3: System.out.println("Your balance is: "+myBankAccount.getBalance());
    case 4 : System.out.println("Thank you! Goodbye.");