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

New Topic/Question
Reply



MultiQuote





|