Проблема с "SavingAccoung" и "ChequingAccount" для

Мне для учебы надо создать "ChequingAccount" и "SavingAccount" сапклассы для основного "Account" класса. Также, у каждого из сапкласов есть номер аккаунта, напрмер, у класса "ChequingAccount" начинается с "CA-###", а "SavingAccount" начинается с "SA-###" (где ### - обычные цифры). Вопрос в том, что я не знаю как дать понять классу "Account" какой аккаунт есть какой зная только первые две буквы? Вот часть кода у "Account" класса:

public class Account {

    private String accountNumber;
    private double balance;
    private boolean active;
    private ArrayList < String > transactionInfo;

    /**
     * Default constructor to create Account objects
     */
    public Account() {
        super();

    }

    /**
     * Overloaded Account constructor
     *
     * @param accountNumber
     * to set the accountNumber field
     * @param balance
     * to set the balance field
     * @param transactionInfo to add transaction information about every deposit and withdrawl
     */
    public Account(String accountNumber, double balance) {
        super();
        if (accountNumber != null) {
            this.accountNumber = accountNumber;
        }
        setBalance(balance);
        active = true;
        transactionInfo = new ArrayList < String > ();
    }

    /**
     * accessor for the accountNumber field
     *
     * @return the accountNumber as a String
     */
    public String getAccountNumber() {
        return accountNumber;
    }

    /**
     * Method to change account types
     * @param accountNumber the accountNumber to set
     */
    public void setAccountNumber(String accountNumber) {
        if (getAccountNumber().substring(0, 1).equals("SA")) {
            this.accountNumber = ;
        } else if (getAccountNumber().substring(0, 1).equals("CH")) {
            this.accountNumber = "Chequing account";
        } else if (getAccountNumber().substring(0, 1).equals("GL")) {
            this.accountNumber = "Gold account";
        } else {
            System.out.println("ERROR");
        }
    }
}

Вот код "ChequingAccount" класса:

public class ChequingAccount extends Account {
    /**
     * Variables
     */
    private final double FEE = 1.0;
    int numberOfCheques;

    /**
     * Default constructor
     */
    public ChequingAccount() {
        super();
    }

    /**
     * Overloaded constructor
     *
     * @param accountNumber String to initialize the accountNumber field
     * @param balance String to initialize the balance field
     * @param numberOfCheques to initialize the numberOfCheques fields
     */
    public ChequingAccount(String accountNumber, double balance, int numberOfCheques) {
        super(accountNumber, balance);
        setNumberOfCheques(3);
    }

    /**
     * Override setBalance method
     *
     * @param balance the balance to set
     */
    public void setBalance(double balance) {
        if (balance > 0) {
            super.setBalance(balance);
        } else {
            System.out.println("Number should be more than 0");
        }
    }

    /**
     * @return the numberOfCheques as an int
     */
    public int getNumberOfCheques() {
        return numberOfCheques;
    }

    /**
     *
     * @param numberOfCheques to set numberOfCheques field
     */
    public void setNumberOfCheques(int numberOfCheques) {
        if (numberOfCheques >= 0) {
            this.numberOfCheques = numberOfCheques;
        } else {
            System.out.println("Number should be more than 0");
        }
    }

    /**
     * Override substractFromBalance method
     * @param amount the amount to substract from account
     */
    public void subtractFromBalance(double amount) {
        if (amount > 0) {
            if (getNumberOfCheques() <= 2) {
                super.subtractFromBalance(amount);
                setNumberOfCheques(getNumberOfCheques() + 1);
            } else {
                System.out.println("You have used your monthly limit");
            }
        } else {
            System.out.println("ERROR. Invalid number");
        }
    }

    @Override
    public String toString() {
        return "ChequingAccount [numberOfCheques=" + numberOfCheques + ", getAccountNumber()=" + getAccountNumber() +
            ", toString()=" + super.toString() + "]";
    }

}

Я совсем недавно начал изучать джаву и надеюсь что вы поможите мне решить мою проблему. Спасибо!


Ответы (0 шт):