What I am trying to do is create a bank class (which uses an array to store the accounts) that has a create method which is used to create a new account in the bank. The method requires the user to input data (account number, name, phone number, and balance) and will create a new account in the bank, but the method has to check to see if the account number is already in use and if it is print an
error message and return (this is where I am having problems).
I have three files an Account class, a Bank class, and a BankDriver class, posted below are the three classes
public class Account { private final double RATE = 0.03; // interest rate of 3.0% private long acctNumber; private double balance; private String name; private String phoneNumber; public Account () { name = ""; acctNumber = 0000; phoneNumber = "555-1111"; balance = 0.0; } //--------------------------------------------------------------------------------------------- // Creates account by defining the owner, account number, phone number, and starting balance //--------------------------------------------------------------------------------------------- public Account (String owner, long account, String phone, double initial) { name = owner; acctNumber = account; phoneNumber = phone; balance = initial; } //----------------------------------------------------------------------- // Returns balance //----------------------------------------------------------------------- public double getBalance() { return balance; } //---------------------------------------------------------------------- // Returns account number //---------------------------------------------------------------------- public long getAcctNumber() { return acctNumber; } public String toString() { return acctNumber + "\t" + name + "\t" + phoneNumber + "\t" + balance; } }
public class Bank { private Account[] accounts; private int count = 0; public Bank() { accounts = new Account[30]; } public void create (long accountNum, String owner, String phNumber, double initial) { if(accountNum != accounts[count].getAcctNumber()) { accounts[count] = new Account(owner, accountNum, phNumber, initial); count++; } else if(accountNum == accounts[count].getAcctNumber()) System.out.println("Account Number already exsists."); } public String toString() { String report = ""; for (int i = 0; i<count; i++) report += accounts[i] + "\n"; return report; } }
The problem I believe is my create method but I am not sure of the best way to fix it. Any help would be greatly appreciated.