Well i'm having trouble with this code with the following lines:
return new AccountID(this);
return new Customer(this);
^These two from the clone method.
Customer myCustomer = new Customer(newBank.Find(myAccountID));
^Not sure what i'm doing wrong here, it is on 4 different methods of deposit, withdrawal etc.
Not only that, but my return function for Balance & CustomerName seems off. As well as the report method. Everything else is fine though. Here is the whole code from scratch. Any help is appreciated.
public class Bank
{
private static class AccountID implements Comparable<AccountID>, HasClone<AccountID>
{
public AccountID(int iID)
{
ID = iID;
}
public int compareTo(AccountID N)
{
return ID-N.ID;
}
public AccountID Clone()
{
return new AccountID(this);
};
public int ID;
};
private static class Customer implements HasVisit, HasClone<Customer>
{
public Customer(String customerName, double iBalance)
{
CustomerName = customerName;
Balance = iBalance;
};
public void Visit() {
System.out.println("Customer Name : "+CustomerName+" Balance : "+Balance);
};
public Customer Clone()
{
return new Customer(this);
};
public String CustomerName;
public double Balance;
};
public void AddAccount(int accountID, String customerName) throws Exception
{
AccountID myAccountID = new AccountID(accountID);
Customer myCustomer = new Customer(customerName,0);
newBank.Insert(myAccountID, myCustomer);
};
public void RemoveAccount(int accountID) throws Exception
{
AccountID myAccountID = new AccountID(accountID);
newBank.Delete(myAccountID);
};
public void Deposit(int accountID, double amount) throws Exception
{
AccountID myAccountID = new AccountID(accountID);
Customer myCustomer = new Customer(newBank.Find(myAccountID));
myCustomer.Balance = myCustomer.Balance + amount;
newBank.Update(myAccountID, myCustomer);
};
public void Withdraw(int accountID, double amount) throws Exception
{
AccountID myAccountID = new AccountID(accountID);
Customer myCustomer = new Customer(newBank.Find(myAccountID));
myCustomer.Balance = myCustomer.Balance - amount;
newBank.Update(myAccountID, myCustomer);
};
public double Balance(int accountID) throws Exception
{
AccountID myAccountID = new AccountID(accountID);
Customer myCustomer = new Customer(newBank.Find(myAccountID));
return myCustomer.Balance;
};
public String CustomerName(int accountID) throws Exception
{
AccountID myAccountID = new AccountID(accountID);
Customer myCustomer = new Customer(newBank.Find(myAccountID));
return mycustomer;
};
public void Report()
{
Report(AccountID, Customer);
};
private SearchTree<AccountID, Customer> newBank = new SearchTree<AccountID, Customer>();
};