Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Accessing account objects in a ArrayList using Loops

$
0
0
First of all, I am posting the main parts of the assignment so that you can better understand the problems I am getting
with the loop methods: listAllAccounts, listAllOpenAccounts() and listAllClosedAccounts

Assignment

accountController() :Initialises an array[account] (using the new operator) of 10 objects -Completed

createAccountCreate a new account by getting the parameters from the user and then passing them to the new object . Add the account to the Array. Do not allow the user to add more accounts than there are slots in the array. (So each time it creates a new account, it increments the integer that tracks numberOfAccounts by 1)Completed

listAllAccountsUses a loop to list all accounts contained in the ArrayList
For each account, it calls the printAccountDetails method

Error for this method: printAccountDetails() in accountController cannot be applied to (java.lang.Object)

If I remove Object from listAllAccounts Parameter and compile, another error comes up: <identifer> expected

listAllOpenAccounts Uses a loop to list all open accounts contained in the ArrayList
For each open account, it calls the printAccountDetails method

Error for the method: Same error as listAllOpenAccounts()

printAccountDetails(account parameter) This method prints all the details of an account on the screen
It should be private – it is only ever called by the list methods -Completed


listAllClosedAccounts: Method that lists all closed accounts. It will loop through the array and will check if the accountstatus of each item is true or false.

Syntax:
for (int i = 0; i < arraysize; i ++)
{
boolean isOpen = arrayname[i].getAccountStatus();
// if (!isOpen) {do something}
}

Error: Cannot find symbol - class accountStatus


This is what I have done so far

public class accountController
{
   private account[] accountsList;
   private int numberOfAccounts; 
   private int counter = 0;
   private boolean accountStatus = true;
   
    public accountController()
{
       accountsList = new account[10];
      
}

    public void createAccount(int accountNumberUI, String customerNameUI, double initialLodgementUI){
    if(accountNumberUI < 999 || accountNumberUI > 10000){
    
        System.out.println("Please enter a four digit account number");
    }else {
        
       account newAccount = new account(accountNumberUI, customerNameUI, initialLodgementUI);
       accountsList[counter] = newAccount;
       counter++;
} 
}
  
    public void listAllAccounts(Object newAccount)
{   
    if(accountsList[counter] !=null)
    {
     for(counter=0; counter<10; counter++)
    {
        printAccountDetails(newAccount); 
       
    }
 
}         
}

    public void listAllOpenAccounts(Object newAccount)   
{

  while(counter<10)
  {
      if(accountsList[counter].getAccountStatus() &&(accountsList[counter]!=null))
      {
          printAccountDetails(newAccount);
          counter++;
 }
  
}
}

    private void printAccountDetails()
{
    System.out.println("Account number:" + account.getAccountNumber());
 

}

    public void listAllClosedAccounts()
 {
    for(counter =0; counter<10; counter++)
    {
      accountStatus isOpen = newAccount[counter].getAccountStatus();
        
    }


}    

}


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>