I am having difficulty making sure the error message for choice 2 only appears if the number the user inputs is greater than their bank balance. Yet, it will appear even if the amount the user inputted is less than their bank balance. Playing around with it some more has now made my problems worse because the user has to input an answer more than once to get a response. If there are still things about the problem that are unclear please let me know. This is my first programming class and I have yet to figure out solutions on my own yet so any help would be very welcome.
//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.");
}
Aucun commentaire:
Enregistrer un commentaire