Member Avatar for krejar

This is very ugly to look at, but I am having an issue with my array code. What I am trying to do here is add a name element to my Account accounts[]. When I initiate my driver and I pick the create account option, I am getting the output:

*** MENU *************
*1. Create Account *
*2. Login Account *
*3. Exit ATM *
*====================*
*Enter choice (1-3): *
**********************
1
You chose 1
Enter account holder name:
You must enter in a Name:
Enter account holder name:

What I am trying to figure out is, why can't I get my 1st if statement to work and why it skips the 1st if statement all together.

Some values of note are:

private Account[] accounts; 
   private static final int ACTKEY = 1000;
   private static final int MAXACCT = 100;
   private static final double Z = 0.0;
   private static final double FEE = 1.50;
   private static final long ACTNUMIN = 0;
   public String owner;
   public double amount = 0.0;
   public double fee = 0.0;
   public int numAct =0;
   public long accountIn =0;
   public long account =0;
private void createAccount()
   {
	  // System.out.println(numAct); //place holder
	  // System.out.println("Enter account holder name: ");
          // owner = scan.next();
	  for (int i = 0; i < numAct; i++)
	  while(! done)
          {
	     System.out.println("Enter account holder name: ");
             owner = scan.nextLine();
             if (owner.length() == 0)
             {
                System.out.println("You must enter in a Name: ");
                System.out.println("Enter account holder name: ");
                owner = scan.next();
             }
             else if (i == numAct)
             {
                System.out.println("Error: Accounts Full. You cannot create another account.");
             }
             else
             {
                account = ACTKEY + i;
                System.out.println(owner + ", your account number is: " + account);
                i++;
             }// End of else
             //accounts(owner, account, initial);
             done = true;
          }// End of while loop

I did not understand your question.It is going in the if statement for the first time according to what output you are getting. I suppose your problem is something else.

done = true;

and

while(! done)

Assuming initially value of done was false, so !done evaluated to true and you entered while loop for the first time. But when you assign true to done, while will evaluate to false , and you will not go inside the loop at all.

I think you should change it to,

while(done)

All in all, I don't find a good use of while inside for in your case

Member Avatar for krejar

We have found out that a while loop does indeed not help this out. I have since put in a DO loop.

private void createAccount()
 {
  int i = 0;
  //System.out.println(numAct);
  do
  {
   System.out.println("Enter account holder name: ");
   owner = scan.next();
   if(i == numAct)
   {
    System.out.println("Error: Accounts Full. You cannot create another account.");
   }
   else
   {
    account = ACTKEY + i;
    System.out.println(owner + ", your account number is: " + account);
   }// End of else
   i++;
   //accounts[i] = new Account(owner, account, initial);
  }while(i != 1);// End of while loop
  ATM();
  /*int j = 0;
  if(j <= numAct)
  {
   account = ACTKEY + j;
   System.out.println(owner + ", your account number is: " + account);
   j++;
  }// End of if*/
 }// End of createAccount()
Member Avatar for krejar

I didn't want to post my whole code but...

import java.util.*;

public class Bank
{
   private Account[] accounts; 
   private static final int ACTKEY = 1000;
   private static final int MAXACCT = 100;
   private static final double Z = 0.0;
   private static final double FEE = 1.50;
	private static final long ACTNUMIN = 0;
   public String owner;
   public double amount = 0.0;
   public double fee = 0.0;
   public int numAct = 0;
   public long accountIn = 0;
	public long account = 0;
   boolean done = false;
	
   Scanner scan = new Scanner(System.in);
   // Constructor
   public Bank()
   {
      accounts = new Account[numAct];
      amount = Z;
		account = ACTNUMIN;
   }
   /* layout from UML */
   public void ATM()
   {  
   // Loop / Switch Menu
      while (!done)
      {
      // print-out the menu
         System.out.println();
         System.out.println("*** MENU *************");
         System.out.println("*1. Create Account   *");
         System.out.println("*2. Login Account    *");
         System.out.println("*3. Exit ATM         *");
         System.out.println("*====================*");
         System.out.println("*Enter choice (1-3): *");
         System.out.println("**********************");
   
         // get the choice
         int choice = scan.nextInt();
         System.out.println("You chose " + choice);

         // process the choice
         switch (choice)
         {
            case 1: 
               createAccount();
               break;

            case 2: 
               login();
               break;

            case 3: 
               System.out.println("Exit Terminal.");
               done = true;
               break;

            default:
               System.out.println("Invalid choice, try again.");
         } // End of switch
      } // End of while
   }// End of ATM()
   // ????
   private void createAccount()
 {
  int i = 0;
  //System.out.println(numAct);
  do
  {
   System.out.println("Enter account holder name: ");
   owner = scan.next();
   if(i == numAct)
   {
    System.out.println("Error: Accounts Full. You cannot create another account.");
   }
   else
   {
    account = ACTKEY + i;
    System.out.println(owner + ", your account number is: " + account);
   }// End of else
   i++;
   //accounts[i] = new Account(owner, account, initial);
  }while(i != 1);// End of while loop
  ATM();
  /*int j = 0;
  if(j <= numAct)
  {
   account = ACTKEY + j;
   System.out.println(owner + ", your account number is: " + account);
   j++;
  }// End of if*/
 }// End of createAccount()
   private void login()
   {
      accountIn = scan.nextInt();
      for (int l = 0; l < accounts.length; l++)
      {
         if(accountIn == account)
            accountMenu(accounts);
         else
            System.out.println("Error: That accounts number does not exist");
      }
   }// End of login()
   private void accountMenu(Account[] accounts)
   {
   // Loop / Switch Menu
      while (!done)
      {
      // print-out the menu
         System.out.println();
         System.out.println("**** MENU *************");
         System.out.println("*1. Make Deposit      *");
         System.out.println("*2. Make Withdraw     *");
         System.out.println("*3. Display Acct Info *");
         System.out.println("*4. Log Out           *");
         System.out.println("*=====================*");
         System.out.println("*Enter choice (1-4):  *");
         System.out.println("***********************");
         // get the choice
         int choice = scan.nextInt();
         System.out.println("You chose " + choice);
         // process the choice
         switch (choice)
         {
            case 1:
               System.out.println("Enter amount to deposit: ");
               amount = scan.nextDouble();
               //Account.deposit(amount);
               break;

            case 2: 
               System.out.println("Enter amount to withdraw: ");
               amount = scan.nextInt();
               //Account.withdraw(amount + FEE);
               break;

            case 3: 
               System.out.println("Account Information: ");
               accounts.toString();
               done = true;
               break;
     
            case 4:
               ATM();
               done = true;
               break;
     
            default:
               System.out.println("Invalid choice.");
         } // End of switch
      } // End of while
   }// ENd of accountsMenu()
 
   //public void setDeposit(double newBalance){newBalance = balance;}
   public double Withdraw(double Num)
	{
	   if (Num <= 0 || Num > amount)
		   return -1;
		System.out.println("Withdrawing the amount of: " + Num);
		amount = amount - Num;
		return Num;	
	}
	
	public double getWithdraw()
	{
	   return amount;
	}
	
	public double Diposit(double Num)
	{
	   if (Num <= 0)
		   return -1;
		System.out.println("Dipositing amount: " + Num);
		amount = amount + (double)Num;
		return Num;
	}
	
	public double getDiposit()
	{
	   return amount;
	}
	
	public void setNumAct(int NumAct){numAct = NumAct;}
	
	public String toString()
	{
	   String report = "-----------------------\n";
		report += "Bank Accounts\n\n";
		
		report += "Number of Accounts: " + numAct;
		report += "Account List:\n\n";
		
		//for (int a = 0; a < numAct; a++)
		  // report += accounts[a].toString() + "\n";
		
		return report;
	}
  // ?????
}

This is what I am struggling with. I am not having any luck getting passed the create account. My driver allows me to input a name, I get my account number (which is 1000), but when I go to add a second account name, I get the same account number (1000). Right now that is the bane of my code.

Member Avatar for krejar

Update to create account:

It is not liking the

accounts[i] = new Account(owner, account, initial);

The way I have Account set up is

public Account (String owner, long account, double initial)

And I do have all of those variables called.

private void createAccount()
   {
      int i = 0;
      //System.out.println(numAct);
      do
      {
         System.out.println("Enter account holder name: ");
         owner = scan.next();
         if(i == numAct)
         {
            System.out.println("Error: Accounts Full. You cannot create another account.");
         }
         else
         {
            account = ACTKEY + i;
            System.out.println(owner + ", your account number is: " + account);
         }// End of else
         i++;
         accounts[i] = new Account(owner, account, initial);
      }while(i != numAct - 1);// End of while loop
      ATM();
    /*int j = 0;
      if(j <= numAct)
      {
         account = ACTKEY + j;
         System.out.println(owner + ", your account number is: " + account);
         j++;
      }// End of if*/
   }// End of createAccount()

I did not understand your question.It is going in the if statement for the first time according to what output you are getting. I suppose your problem is something else.
and

Assuming initially value of done was false, so !done evaluated to true and you entered while loop for the first time. But when you assign true to done, while will evaluate to false , and you will not go inside the loop at all.

I think you should change it to,

while(done)

All in all, I don't find a good use of while inside for in your case

as DJSAN10 said, the only error you might have made was the initialization of the boolean done... is your while loop executing? if you type no name and press enter it should then ask you for your name again... as their is no reason why it would not execute, but now i see you gave all your code, what exactly is going wrong now?

public int numAct = 0;

and

accounts = new Account[numAct];

..????

and where is your main function?

Member Avatar for krejar

Here it is, in all of it's glory

import java.util.*;

public class BankDriver
{
   
   //  Creates some bank accounts and requests various services.
   public static void main (String[] args)
   {
	   int numAct = 3;  
		Bank accounts = new Bank();
		accounts.setNumAct(numAct);
		accounts.ATM();
		accounts.toString();
	}
}

What the assignment is, is to modify my account class into an ATM class. However, I am not allowed to modify the actual account class. I am to basically use inheritance without actually using inheritance. I am calling upon one class to another. The code above is just to get me inside of my ATM, or Bank class.

The reason I have 3 in here is for later in my assignment when I can only create 3 accounts. If I go over 3, I will get an error, which I want. That part is no problem.

Okay in your constructor for bank, there is a line

accounts = new Account[numAct];

and then you are doing

ccounts.setNumAct(numAct);

Thus when in your constructor , numAct is nothing but 0

commented: good eye +9

Here it is, in all of it's glory

import java.util.*;

public class BankDriver
{
   
   //  Creates some bank accounts and requests various services.
   public static void main (String[] args)
   {
	   int numAct = 3;  
		Bank accounts = new Bank();
		accounts.setNumAct(numAct);
		accounts.ATM();
		accounts.toString();
	}
}

What the assignment is, is to modify my account class into an ATM class. However, I am not allowed to modify the actual account class. I am to basically use inheritance without actually using inheritance. I am calling upon one class to another. The code above is just to get me inside of my ATM, or Bank class.

The reason I have 3 in here is for later in my assignment when I can only create 3 accounts. If I go over 3, I will get an error, which I want. That part is no problem.

I still dont see an error i havent ran the actual code but looking at what you said:

{
   
   //  Creates some bank accounts and requests various services.
   public static void main (String[] args)
   {
	   int numAct = 3;  
		Bank accounts = new Bank();
		accounts.setNumAct(numAct);
		accounts.ATM();
		accounts.toString();
	}
}

And looking at each method call etc, everything looks okay? what is the error in those lines? or what is wrong with the output? how does it look and how must it look?

[EDIT]Read DJSAN10's post ... So that might be the problem, why not make the Bank constructor accept an int argument to assign a value to numAct for each instance

Read DJSAN10's post ... So that might be the problem, why not make the Bank constructor accept an int argument to assign a value to numAct for each instance

Exactly, I was about to suggest the same

Member Avatar for krejar

I am not fishing for an easy fix. Just a reason why I can't pass into my Log In.

I am going to take a break for the night. We have been at this since 10am this morning :(

Driver:

import java.util.*;

public class BankDriver
{
   
   //  Creates some bank accounts and requests various services.
   public static void main (String[] args)
   {
	   int numAct = 3;  
		Bank accounts = new Bank();
		accounts.setNumAct(numAct);
		accounts.ATM();
		accounts.toString();
	}
}

Account class:

import java.text.NumberFormat;


   public class Account
   {
   // instance data
   
      private final double RATE = 0.035;  // interest rate of 3.5%
      private final double ZERO = 0.00;
      private long acctNumber;
      private double balance;
      private String name;
      NumberFormat fmt = NumberFormat.getCurrencyInstance();
   
   //  Sets up the account by defining its owner, account number,
   //  and initial balance.
      public Account (String owner, long account, double initial)
      {
         name = owner;
         acctNumber = account;
         if (initial < 0)
         {
            System.out.println("ERROR! Negative number input " + 
				name + " " + fmt.format(initial));
            initial = ZERO;
         }
         balance = initial;
      }
   
   //  Deposits the specified amount into the account. Returns the
   //  new balance.
      public double deposit (double amount)
      {
         balance = balance + amount;
         if (amount < 0)
         {
            System.out.println("ERROR! Negative number input " + 
				name + " " + fmt.format(amount));
            balance = balance - amount;
         }
         return balance;
      }
   
   //  Withdraws the specified amount from the account and applies
   //  the fee. Returns the new balance.
      public double withdraw (double amount, double fee)
      {
         balance = balance - Math.abs(amount) - fee;
         if (amount > balance)
         {
            System.out.println("ERROR! Insufficient funds, " + name +
               ". You cannot withdraw more than " + fmt.format((amount + fee)));
            balance = balance + amount + fee;
         }
         return balance;
      }
   
   //  Adds interest to the account and returns the new balance.
      public double addInterest ()
      {
         balance += (balance * RATE);
         return balance;
      }
   
   //  Returns the current balance of the account.
      public double getBalance () 
      {
         if (balance < 0)
         {
            System.out.println("ERROR! Negative number input. " + 
				   fmt.format(balance));
         }
         return balance; 
      }
   
   //  Sets the current balance of the account to a new value.
      public void setBalance (double newBalance) 
      {
         if (newBalance < 0)
         {
            System.out.println("ERROR! Negative number input. " + 
				   fmt.format(newBalance)); 
            newBalance = balance;
         }
         balance = newBalance;
      }
   
   //  Returns a one-line description of the account as a string.
      public String toString ()
      {
         return (acctNumber + "\t" + name + "\t" + fmt.format(balance));
      }
   }

Bank class:

import java.util.*;

public class Bank
{
   private Account[] accounts; 
   private static final int ACTKEY = 1000;
   private static final int MAXACCT = 100;
   private static final double Z = 0.0;
   private static final double FEE = 1.50;
	private static final long ACTNUMIN = 0;
   public String owner;
	public double initial = 0.0;
   public double amount = 0.0;
   public double fee = 0.0;
   public int numAct = 0;
   public long accountIn = 0;
	public long account = 0;
   boolean done = false;
	
   Scanner scan = new Scanner(System.in);
   // Constructor
   public Bank()
   {
      accounts = new Account[numAct];
      amount = Z;
		account = ACTNUMIN;
   }
   /* layout from UML */
   public void ATM()
   {  
   // Loop / Switch Menu
      while (!done)
      {
      // print-out the menu
         System.out.println();
         System.out.println("*** MENU *************");
         System.out.println("*1. Create Account   *");
         System.out.println("*2. Login Account    *");
         System.out.println("*3. Exit ATM         *");
         System.out.println("*====================*");
         System.out.println("*Enter choice (1-3): *");
         System.out.println("**********************");
   
         // get the choice
         int choice = scan.nextInt();
         System.out.println("You chose " + choice);

         // process the choice
         switch (choice)
         {
            case 1: 
               createAccount();
               break;

            case 2: 
               login();
               break;

            case 3: 
               System.out.println("Exit Terminal.");
               done = true;
               break;

            default:
               System.out.println("Invalid choice, try again.");
         } // End of switch
      } // End of while
   }// End of ATM()
   // ????
   private void createAccount()
   {
      int i = 0;
      //System.out.println(numAct);
      do
      {
         System.out.println("Enter account holder name: ");
         owner = scan.next();
         if(i == numAct)
         {
            System.out.println("Error: Accounts Full. You cannot create another account.");
         }
         else
         {
            account = ACTKEY + i;
            System.out.println(owner + ", your account number is: " + account);
         }// End of else
         i++;
         accounts[i] = new Account(owner, account, initial);
      }while(i != numAct - 1);// End of while loop
      ATM();
    /*int j = 0;
      if(j <= numAct)
      {
         account = ACTKEY + j;
         System.out.println(owner + ", your account number is: " + account);
         j++;
      }// End of if*/
   }// End of createAccount()
   private void login()
   {
      accountIn = scan.nextInt();
      for (int l = 0; l < accounts.length; l++)
      {
         if(accountIn == account)
            accountMenu(accounts);
         else
            System.out.println("Error: That accounts number does not exist");
      }
   }// End of login()
   private void accountMenu(Account[] accounts)
   {
   // Loop / Switch Menu
      while (!done)
      {
      // print-out the menu
         System.out.println();
         System.out.println("**** MENU *************");
         System.out.println("*1. Make Deposit      *");
         System.out.println("*2. Make Withdraw     *");
         System.out.println("*3. Display Acct Info *");
         System.out.println("*4. Log Out           *");
         System.out.println("*=====================*");
         System.out.println("*Enter choice (1-4):  *");
         System.out.println("***********************");
         // get the choice
         int choice = scan.nextInt();
         System.out.println("You chose " + choice);
         // process the choice
         switch (choice)
         {
            case 1:
               System.out.println("Enter amount to deposit: ");
               amount = scan.nextDouble();
               //Account.deposit(amount);
               break;

            case 2: 
               System.out.println("Enter amount to withdraw: ");
               amount = scan.nextInt();
               //Account.withdraw(amount + FEE);
               break;

            case 3: 
               System.out.println("Account Information: ");
               accounts.toString();
               done = true;
               break;
     
            case 4:
               ATM();
               done = true;
               break;
     
            default:
               System.out.println("Invalid choice.");
         } // End of switch
      } // End of while
   }// ENd of accountsMenu()
 
   //public void setDeposit(double newBalance){newBalance = balance;}
   public double Withdraw(double Num)
	{
	   if (Num <= 0 || Num > amount)
		   return -1;
		System.out.println("Withdrawing the amount of: " + Num);
		amount = amount - Num;
		return Num;	
	}
	
	public double getWithdraw()
	{
	   return amount;
	}
	
	public double Diposit(double Num)
	{
	   if (Num <= 0)
		   return -1;
		System.out.println("Dipositing amount: " + Num);
		amount = amount + (double)Num;
		return Num;
	}
	
	public double getDiposit()
	{
	   return amount;
	}
	
	public void setNumAct(int NumAct){numAct = NumAct;}
	
	public String toString()
	{
	   String report = "-----------------------\n";
		report += "Bank Accounts\n\n";
		
		report += "Number of Accounts: " + numAct;
		report += "Account List:\n\n";
		
		//for (int a = 0; a < numAct; a++)
		  // report += accounts[a].toString() + "\n";
		
		return report;
	}
  // ?????
}

This compiles just fine and dandy. My output as it stands is:

*** MENU *************
*1. Create Account *
*2. Login Account *
*3. Exit ATM *
*====================*
*Enter choice (1-3): *
**********************
1
You chose 1
Enter account holder name:
Bill
Bill, your account number is: 1000
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at Bank.createAccount(Bank.java:88)
at Bank.ATM(Bank.java:52)
at BankDriver.main(BankDriver.java:20)


My group is going to take a break for the night and pick it up in about 7 hours again. I appreciate the help folks. Hopefully a rested mind will come up with something better.

What this program is supposed to do is, create an account. The user gets an account number. Then, the user picks log into account with account number. Within the login menu, they can then deposit, withdraw, display their name and account number and balance, or they can exit back to the 1st menu.

My problem is that I can't get into the second menu.

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1

There you go. That IS your problem.

Follow the suggestion that cOrRuPtG3n3t!x just gave and I think you will be through. Your array is not being created as an array of 3 elements since you are attempting to create the array first and then setting its size parameter to 3.

And next time make sure you post you error/exception right from the beginning so it becomes much easier for us to help you out. :)

you read the menu choice int from the scanner, but this leaves the newline delimiter unread. Your next read is likely to return "" - ie everything before the next newline. Flush the newline after reading the int.

There you go. That IS your problem.

Follow the suggestion that cOrRuPtG3n3t!x just gave and I think you will be through. Your array is not being created as an array of 3 elements since you are attempting to create the array first and then setting its size parameter to 3.

And next time make sure you post you error/exception right from the beginning so it becomes much easier for us to help you out. :)

Adding to what DJSAN10 said, when you add the int argument in the bank constructor,of course you wouldnt need your setNumAct method call... and also the int numAct would be private. also i dont see this as a good thing:

if(i == numAct)
         {//you check numAct for i......
            System.out.println("Error: Accounts Full. You cannot create another account.");
         }
         else
         {//there is still space to add another account
            account = ACTKEY + i;
            System.out.println(owner + ", your account number is: " + account);
         
         i++;//You increment i and then call account[i]? thats not good this increment statement should be after your accounts[i] because if you checked numAct==i and i was 3 you still increment i before you call accounts[i] which will then be theoretically accounts[4] which doesnt 'exist'
         accounts[i] = new Account(owner, account, initial);
         //i++;//should be here
         }// End of else should be here or it will execute even if the numAct==i
Member Avatar for krejar

Fixed the out of bounds issue. Was a stupid easy fix that slapped me in the face. However the createAccount() is still punching me in the nose. It still won't allow me to just pass in 1 create account input. When I type in a string, the loop happens again and asks for a 2nd string input. The account number increments though which is good. I don't know. Going to bed and getting a fresh start in 6 hours.

private void createAccount()
   {
	   for (int i = 0; i < accounts.length; i++)    /////////////////// START HERE in the morning!!!!!!
      //System.out.println(numAct);
      do
      {
         System.out.println("Enter account holder name: ");
         owner = scan.next();
         if(i == MAXACCT)
         {
            System.out.println("Error: Accounts Full. You cannot create another account.");
         }
         else
         {
            account = ACTKEY + i;
            System.out.println(owner + ", your account number is: " + account);
         }// End of else
         accounts[i] = new Account(owner, account, initial);
         i++;
      }while(i != numAct - 1);// End of while loop
      ATM();
    /*int j = 0;
      if(j <= numAct)
      {
         account = ACTKEY + j;
         System.out.println(owner + ", your account number is: " + account);
         j++;
      }// End of if*/
   }// End of createAccount()

Fixed the out of bounds issue. Was a stupid easy fix that slapped me in the face. However the createAccount() is still punching me in the nose. It still won't allow me to just pass in 1 create account input. When I type in a string, the loop happens again and asks for a 2nd string input. The account number increments though which is good. I don't know. Going to bed and getting a fresh start in 6 hours.

private void createAccount()
   {
	   for (int i = 0; i < accounts.length; i++)    /////////////////// START HERE in the morning!!!!!!
      //System.out.println(numAct);
      do
      {
         System.out.println("Enter account holder name: ");
         owner = scan.next();
         if(i == MAXACCT)
         {
            System.out.println("Error: Accounts Full. You cannot create another account.");
         }
         else
         {
            account = ACTKEY + i;
            System.out.println(owner + ", your account number is: " + account);
         }// End of else
         i++;
         accounts[i] = new Account(owner, account, initial);
      }while(i != numAct - 1);// End of while loop
      ATM();
    /*int j = 0;
      if(j <= numAct)
      {
         account = ACTKEY + j;
         System.out.println(owner + ", your account number is: " + account);
         j++;
      }// End of if*/
   }// End of createAccount()

when you say:

It still won't allow me to just pass in 1 create account input

.... do you mean it asks you to create 3 accounts all the time instead of just 1 at a time?...... if so its this:

for (int i = 0; i < accounts.length; i++)

and looking at the above you are increasing 'i' twice? in the for statement and before your accounts:

i++;
         accounts[i] = new Account(owner, account, initial);

thats really bad..... and its outside the else statement still.. see my above post please... but now you cant have i++ and the for statement... one of them gotta go

Member Avatar for krejar

I put that for statement in there as a starting point for me in the morning. I do realize with the current setup as it is, I will be in a continuous loop of just entering account names and receiving account numbers with no way of getting back to the main menu :P

What I would like to suggest to you now is something you can call as "dry run".
You take a piece of paper and pencil, start from main , and work through the entire flow of your program. Like when a function is called go to that function, see the initial values of all variables, compute on paper how they are being modified and whether the modifications are correct. Move according to the flow how your program is going to take and check out all possibilities. You can try doing this first when you wake up tomorrow and are all up to code again :)

I put that for statement in there as a starting point for me in the morning. I do realize with the current setup as it is, I will be in a continuous loop of just entering account names and receiving account numbers with no way of getting back to the main menu :P

and also your accounts[] will be empty in some places or it will throw an outofbounds also when editing your Bank construct it should looj similar too:

public Bank(int num) {
        numAct=num;
        accounts=new Account[numAct];//set array size
..
}

and just something else i found in createAccount(): use

if(i>numAct) {

and change your while:

while (i != numAct);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.