4 Replies - 222 Views - Last Post: 07 December 2012 - 04:05 AM Rate Topic: -----

#1 Lordhaha  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 06-December 12

passing to arraylist&to string method

Posted 06 December 2012 - 07:01 AM

Hi guys,

I am new to posting on this site although I have scrolled through answers many times.
Due to a number of real life issues I have missed a number of lectures at collage. I am trying to get the following 'Bank system to work using arraylist template that was supplied by lecturer. I have tried so many ways of doing this using eclipse I have really confused myself. I do not have a tester written yet, as I can not get rid of certain errors.
I need help with
1.error in the "2nd"add account 'Final bank class' Is this to add mortage/current accounts to Final customer?

I am hopeful that I might work the rest out after I clear this hurdle,

import java.util.ArrayList;

 public class  FinalBank {
	 
	 private String BankName;
	 private String BankAddress;
     //private ArrayList<FinalCustomer> accounts1; 
	 public FinalBank(String BN, String BA){
		 
		 BankName=BN;
		 BankAddress=BA;
	 }
	 ArrayList <FinalCustomer>accounts1 = new ArrayList<FinalCustomer>(); 
  
		   /** 
		      Adds an account to this bank. 
		      @param a the account to add 
		   */
		   public void addAccount(FinalCustomer a) 
		   { 
		      accounts1.add(a); 
		   } 
		    /** 
		      Gets the sum of the balances of all accounts in this bank. 
	      @return the total balance 
		   */
		   public double getTotalBalance(double total) 
		   { 
		      total = 0; 
		      for (FinalCustomer a : accounts1) 
		      { 
		         total = total + a.getBalance(); 
		      } 
		      return total; 
		   } 

		   public int count(double atLeast) 
		   { 
		      int matches = 0; 
		      for (FinalCustomer a : accounts1) 
		      { 
		         if (a.getBalance() >= atLeast) matches++; // found a match 
		      } 
		      return matches; 
		   } 
		    /** 
		      Finds a bank account with a given number. 
		      		   */
		   public FinalCustomer find(int accountNumber) 
		   { 
		      for (FinalCustomer a : accounts1) 
		      { 
		         if (a.getCustomerAccountNumber() == accountNumber) // found a match 
		            return a; 
		      } 
		      return null; // no match in the entire array list 
		   } 
		     
		   
		     // Gets the bank account with the largest balance. 
		   public FinalCustomer getMaximum() 
		   { 
		      if (accounts1.size() == 0) return null; 
		      FinalCustomer largestYet = accounts1.get(0); 
		        
		      for (int i = 1; i < accounts1.size(); i++) 
		      { 
		    	  FinalCustomer a = accounts1.get(i); 
		         if (a.getBalance() > largestYet.getBalance(i)) 
		            largestYet = a; 
		      } 
		      return largestYet; 
		   } 
		     
		   
		     // Adds an account to the bank. 
 //*************************************MAIN PROBLEM**************************************
		   public void addAccount(CustomerPhoneNumber,double TotalBalance) 
		   { 
			   accounts1.add(new FinalCustomer(CustomerName,CustomerAddress,
		   } 

	
		   public void deposit(int accountNumber, double amount) 
		   { 
			  find(accountNumber).deposit(amount);
		   } 

		 

		   public void withdraw(int accountNumber, double amount) 
		   { 
			   
			find(accountNumber).withdraw(amount);
		   
		   }
		   
		     // Gets an account balance 
		
		   public double getBalance(int accountNumber) 
		   {
			   for (FinalCustomer b : accounts1) 
			      { 
			         if (b.getCustomerAccountNumber() == accountNumber) // found a match 
			        	 
			        	 return(b.getBalance());
			      } 
			   return (Double) null; 
		   	   } 

	public void display(){
	    System.out.println("Bank: "+BankName);
	    System.out.println("Address: "+BankAddress);
	     }
	
	 //Problem*******************************************************
	 // public String getAllAccountData(){ 
	 //	String composed = display() + "\nAccount Type: " + getAccountType() + "\nName: " + getCustomerName() +
	 //	 "\nAccount Number: " + CustomerAccountNumber() + "\nCurrent Balance: " + getBalance(balance);
	 //		return composed;
         //   }	

}



public abstract class FinalCustomer extends FinalBank {
	
	public String CustomerName;
	public String CustomerAddress;
	public int CustomerAccountNumber;
	public int CustomerPhoneNumber;
	public double TotalBalance;
	
	public FinalCustomer(String BN, String BA, String CN, String CA, int CAN, int CPN, double TB){
		
		super(BN, BA);
		CustomerName=CN;
		CustomerAddress=CA;
		CustomerAccountNumber=CAN;
		CustomerPhoneNumber=CPN;
		TotalBalance=TB;

	 }
	 abstract public  double getBalance();
	 abstract public  double deposit(double anAmount);
	 abstract public boolean withdraw(double anAmount);
	 abstract public String getAccountType();  
	 
	public void setCustomerName(String NewName){
		 CustomerName=NewName;
	 }
	public void setCustomerAddress(String NewAddress){
		 CustomerAddress=NewAddress;
	 }
	public void setCustomerPhoneNumber( int NewPhoneNumber){
		 CustomerPhoneNumber=NewPhoneNumber;
	 }
	
	 public int getCustomerAccountNumber(){
		 return CustomerAccountNumber;
	}
		
	 public String getCustomerName(){
		 return CustomerName;
	}	
	 public String getCustomerAddress(){
		 return CustomerAddress;
	}
	/* public  double setTotalBalance(double CurrentBalance,double MortageBalance){
		TotalBalance=(FinalCurrentBalance.getBalance)+(FinalMortageBalance.getBalance);//must change once current & mortage set up
		return TotalBalance; 



 class FinalCurrentAccount extends FinalCustomer {
	 
	private String CurrentAccountNumber;
	private double CurrentBalance;
	
	public FinalCurrentAccount(String BN, String BA, String CN, String CA, int CAN, int CPN, double TB, String C, double CB){
		 
		super(BN,BA,CN,CA,CAN,CPN,TB);
		CurrentAccountNumber=C;
		CurrentBalance=CB;
	}

	 public  double getBalance(){
		 return CurrentBalance;
	 }
	 public  double deposit(double anAmount){
		CurrentBalance+=anAmount;
		 return CurrentBalance; 
	 }
	public boolean withdraw(double anAmount){
	     	if(CurrentBalance>=anAmount){
	         	CurrentBalance=CurrentBalance-anAmount;
	         	System.out.println("Your withdrawl has been accepted.");
	         	System.out.println("Current Balance is: "+CurrentBalance);
	         		return true;}
	         		else{
	         			System.out.println("Your withdrawl has been declined.");
	         			System.out.println("Current Balance is to low: "+ CurrentBalance);
	         			return false;
	         			}
	 }

	public String getAccountType() {
			return "Current Account "+ CurrentAccountNumber;
		}
	public String getCurrentAccountNumber() {
		return CurrentAccountNumber;
	}
} 


 class FinalMortageAccount extends FinalCustomer {
	 
	private String MortageAccountNumber;
	private double MortageBalance;
	private boolean IdPapers;
	
	public FinalMortageAccount(String BN, String BA, String CN, String CA, int CAN, int CPN, double TB, String M, double MB, boolean I){
		 
		super(BN,BA,CN,CA,CAN,CPN,TB);
		MortageAccountNumber=M;
		MortageBalance=MB;
		IdPapers=I;
	}
	
	public boolean checkIdPapers(boolean x){
		return x;
	}

	 public  double getBalance(){
		 return MortageBalance;
	 }
	 public  double deposit(double anAmount){
		MortageBalance+=anAmount;
		 return MortageBalance; 
	 }
	public boolean withdraw(double anAmount){
	     	if(MortageBalance>=anAmount && IdPapers==true){
	         	MortageBalance=MortageBalance-anAmount;
	         	System.out.println("Your withdrawl has been accepted.");
	         	System.out.println("Current Balance is: "+MortageBalance);
	         		return true;}
	         		else{
	         			System.out.println("Your withdrawl has been declined.");
	         			System.out.println("Current Balance is to low: "+ MortageBalance);
	         			return false;
	         			}
	 }

	public String getAccountType() {
			return "Mortage Account "+ MortageAccountNumber;
		}
	public String getCurrentAccountNumber() {
		return MortageAccountNumber;
	}
} 


Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: passing to arraylist&to string method

#2 SwiftStriker00  Icon User is offline

  • No idea why my code works
  • member icon

Reputation: 432
  • View blog
  • Posts: 1,596
  • Joined: 25-December 08

Re: passing to arraylist&to string method

Posted 06 December 2012 - 07:19 AM

In your code:
 public void addAccount(CustomerPhoneNumber,double TotalBalance) 
		   { 
			   //code
		   } 


You are missing the type identifier for customerPhoneNumber. It should read:
 public void addAccount( int CustomerPhoneNumber, double TotalBalance) 
		   { 
			   //code
		   } 


However you will need to pass more information in to the FinalCustomer when adding it to your account
Was This Post Helpful? 0
  • +
  • -

#3 Lordhaha  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 06-December 12

Re: passing to arraylist&to string method

Posted 06 December 2012 - 09:12 AM

Thanks for the reply
I actually had all information from final customer in there string name etc but deleted it later. Will putting them back in fix it???? if I put it back in??? I am 99.9% sure all were in correct before and it still gave me an error.

View PostLordhaha, on 06 December 2012 - 09:09 AM, said:

Thanks for the reply
I actually had all information from final customer in there string name etc but deleted it later. Will putting them back in fix it???? if I put it back in??? I am 99.9% sure all were in correct before and it still gave me an error.

Here is on from an earlier attempted
		   public void addAccount(String CustomerName,String CustomerAddress,int CustomerAccountNumber,int CustomerPhoneNumber,double TotalBalance) 
		   { 
			   accounts1.add(new FinalCustomer(CustomerName,CustomerAddress, CustomerAccountNumber, CustomerPhoneNumber, TotalBalance));//must add extra details
	
}
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: passing to arraylist&to string method

Posted 06 December 2012 - 10:24 AM

This is your code
public void addAccount(String CustomerName,String CustomerAddress,int CustomerAccountNumber,int CustomerPhoneNumber,double TotalBalance) 
{ 
 accounts1.add(new FinalCustomer(CustomerName,CustomerAddress, CustomerAccountNumber, CustomerPhoneNumber, TotalBalance));//must add extra details


from weher we can extract
new FinalCustomer(CustomerName,CustomerAddress, CustomerAccountNumber, CustomerPhoneNumber, TotalBalance)


here is your FinalCustomer construictor
public FinalCustomer(String BN, String BA, String CN, String CA, int CAN, int CPN, double TB){  


Do you see that the number (and the type) of the parameter do not match ?
Was This Post Helpful? 1
  • +
  • -

#5 Lordhaha  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 06-December 12

Re: passing to arraylist&to string method

Posted 07 December 2012 - 04:05 AM

Thanks guys,

There was a problem with the email from a fellow class member!!! There should not have been a "2nd" add.account!!!! He had mistakenly cut and paste!!! Thanks for the input, I shall struggle on for another few hours but I may very well be back to you :oops:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1