This site requires JavaScript, please enable it in your browser!
Greenfoot back
divinity
divinity wrote ...

2021/7/29

Tell me what is wrong here, what I am missing.

1
2
danpost danpost

2021/7/30

#
Remove lines 52 thru 54. Then add the following at line 20:
while (true) {
Then, at line 28, you can add this:
while (mychoice != 4) {
and put a closing bracket, one at each line 52 and 53 (where you removed the lines above).
divinity divinity

2021/7/31

#
isnt this line supposed to go where i had removed lines 53-54
while (mychoice != 4) {
danpost danpost

2021/7/31

#
divinity wrote...
isnt this line supposed to go where i had removed lines 53-54 << Code Omitted >>
No -- where I said.
divinity divinity

2021/7/31

#
when I ran it, this is the result, first error, when u press 1 yes it gives u the balance, when u press 2, it ask how much the user want to withdrawn, u put the amount, it should give u the balance reaming after u withdrawn, and if u withdrawn more than what it have an error message should come and say not enough funds available, that is not coming up when more that enough is withdrawn, when u deposit whatever amount it supposed to say how much it have in the account, that is not showing, and when u hit the 4 (exit button) it supposed to ask for the ID and when u entered the ID it supposed to stop that is not happening. Again something is wrong and it keeps looping. this is the result when i ran it
Enter your enter account ID
1
***Main Menu**** 1:Check balance* 2:Withdraw * 3 Deposit  * 4: Exit *
2
Enter the amount to be withdrawn
60
***Main Menu**** 1:Check balance* 2:Withdraw * 3 Deposit  * 4: Exit *
3
Enter the amount to be deposited
10
***Main Menu**** 1:Check balance* 2:Withdraw * 3 Deposit  * 4: Exit *
4
Enter your enter account ID
1
Enter your enter account ID
1
Enter your enter account ID
2
Enter your enter account ID
0
Enter your enter account IDBUILD STOPPED (total time: 1 minute 19 seconds)
danpost danpost

2021/7/31

#
Show updated main.
divinity divinity

2021/7/31

#
updated main
public class BankATM {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       Scanner scannerin = new Scanner(System.in);
       
       
       int mychoice=0;
       double withdraw=0;
       double acctbalance = 50;
       
       Account[] newacct = new Account[10];
       
       for(int i = 0; i<newacct.length; i++){
           newacct[i] = new Account();
           newacct[i].setacctID(i);
           
       }
       
            while(true){
             
                 System.out.print("Enter your enter account ID");
             int acctID = scannerin.nextInt();
          
             while(acctID != newacct[acctID].getacctID()){
                 System.out.print("Enter the correct account ID");
                 acctID = scannerin.nextInt();
             }
             
             while(mychoice !=4){
                if(acctID == newacct[acctID].getacctID()){
                 
                 System.out.print("***Main Menu***");
                 System.out.print("* 1:Check balance");
                 System.out.print("* 2:Withdraw ");
                 System.out.print("* 3 Deposit  ");
                 System.out.print("* 4: Exit *");
                 mychoice = scannerin.nextInt();
            } 
             
             if(mychoice == 1){
                 System.out.print("The account balance is: $"+newacct[acctID].getacctbalance());
                
            }else if(mychoice == 2){
                System.out.print("Enter the amount to be withdrawn");
                double total_amt = scannerin.nextDouble();
                newacct[acctID].withdraw(total_amt);                
                if(withdraw > total_amt){
                    System.out.print("Insufficient funds available"+ "The balance is: $"+acctbalance);
                }
            }else if(mychoice == 3){
                System.out.print("Enter the amount to be deposited");
                double total_amt = scannerin.nextDouble();
                newacct[acctID].deposit(total_amt);
                
            }
                 
        }
                
     }
       
  }
    
 }
danpost danpost

2021/7/31

#
Cut lines 27 thru 30 and replace with the following:
if (acctID == -1) break; // enter "-1" to end program
if (acctID < -1 || acctID > 9)
{
    System.out.println("Invalid account number.");
    continue;
}
mychoice = 0;
You can change line 24 to instruct how to end program:
System.out.println("Enter your account ID (enter '-1' to end program)");
divinity divinity

2021/8/2

#
hi danpost: it is working but one problem is that when the user try to withdraw more than what it have in the bank, an error message supposed to popup and say" insufficient funds available" but it is not happening, how do I get to say insufficicent funds available when the user enter nore than what it have. here is the updated version.
public class BankATM {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       Scanner scannerin = new Scanner(System.in);
       
       
       int mychoice=0;
       double withdraw=0;
       double acctbalance = 50;
       
       Account[] newacct = new Account[10];
       
       for(int i = 0; i<newacct.length; i++){
           newacct[i] = new Account();
           newacct[i].setacctID(i);
           
       }
       
            while(true){
             
                 System.out.print("Enter your enter account ID or enter -1 to end the program");
                 int acctID = scannerin.nextInt();
          
             if(acctID == -1){
                 break;
             }
                 
            if(acctID < -1 || acctID > 9){
                  System.out.print("Invalid account number");
                  continue;
              }
            mychoice =0;
             
             while(mychoice !=4){
                if(acctID == newacct[acctID].getacctID()){
                 
                 System.out.print("***Main Menu***");
                 System.out.print("* 1:Check balance");
                 System.out.print("* 2:Withdraw ");
                 System.out.print("* 3 Deposit  ");
                 System.out.print("* 4: Exit *");
                 mychoice = scannerin.nextInt();
            } 
             
             if(mychoice == 1){
                 System.out.print("The account balance is: $"+newacct[acctID].getacctbalance());
                
            }else if(mychoice == 2){
                System.out.print("Enter the amount to be withdrawn");
                double total_amt = scannerin.nextDouble();
                newacct[acctID].withdraw(total_amt);                
                if(withdraw > total_amt){
                    System.out.print("Insufficient funds available"+ "The balance is: $"+acctbalance);
                }
            }else if(mychoice == 3){
                System.out.print("Enter the amount to be deposited");
                double total_amt = scannerin.nextDouble();
                newacct[acctID].deposit(total_amt);
                
            }
                 
        }
                
     }
       
  }
danpost danpost

2021/8/3

#
Remove lines 11, 12 and 54. Change line 55 to:
if (total_amt > newacct{acctID].getacctbalance()){
and insert the following after line 57:
else{
    newacct[acctID].withdraw(total_amt)
    System.out.println("New balance is: $"+newacct[acctID].getacctbalance());
}
divinity divinity

2021/8/3

#
Many thanks danpost finally got it to work properly and it is thanks for all of the help. and thanks for the patience u have shown me. thanks again
System.out,printlin("BIG HUGS");
You need to login to post a reply.
1
2