#Issues with setting up class

1 messages · Page 1 of 1 (latest)

cursive condor
#

I have minimal experience with java and im having issues setting up a subclass

hollow lotusBOT
#

<@&987246399047479336> please have a look, thanks.

compact girder
#

are they located in the Account superclass?

#

in that case they need to be protected

#

or public

#

in order to be available in the subclass

cursive condor
#

even when the variable names are unique it still gives me an error

#
    private int id;
    private double balance;
    private static double annualInterestRate;
    private Date dateCreated;

    public Account() {
        this.dateCreated = new Date();
    }

    public Account(int newId, double newBalance) {
        this.id = newId;
        this.balance = newBalance;
        this.dateCreated = new Date();
    }

    public int getId() {
        return this.id;
    }

    public double getBalance() {
        return this.balance;
    }

    public static double getAnnualInterestRate() {
        return annualInterestRate;
    }

    public void setId(int newId) {
        this.id = newId;
    }

    public void setBalance(double newBalance) {
        this.balance = newBalance;
    }

    public static void setAnnualInterestRate(double newAnnualInterestRate) {
        annualInterestRate = newAnnualInterestRate;
    }

    public double getMonthlyInterest() {
        return this.balance * (annualInterestRate / 1200.0);
    }

    public Date getDateCreated() {
        return this.dateCreated;
    }

    public void withdraw(double amount) {
        this.balance -= amount;
    }

    public void deposit(double amount) {
        this.balance += amount;
    }
}

class SavingsAccount extends Account{

    public SavingsAccount(int accocunt, double balance){
        super();
    }

    public boolean hasAmmount(int withdraw){
        if( withdraw > super.getBalance()){
            return false;
        }
        return true;
    }

    public String toString(){
        return "The balance of the Savings account is: " + super.getBalance();
    }



}

class CheckingAccount extends Account{

    public CheckingAccount(int account, double balance, double overdraft){
        this.account = account;
        this.balance = balance;
        this.overdraft = overdraft;


    }
hollow lotusBOT
compact girder
#
class Account {
    private int id;
    private double balance;
    private static double annualInterestRate;
    private Date dateCreated;

they are private

#

as said make them protected

cursive condor
#

so why is overdraft still an issue. is it because i havent initialized it as a variable in the subclass?

#

yep that fixed it

compact girder
#

yeah

cursive condor
#

alright thank you!

upbeat stone
#

oh sheesh we got emotes now

compact girder
upbeat stone
#

we can use emojis

#

to react

compact girder
#

yeah updated that

upbeat stone
#

noice

wicked wasp
# compact girder as said make them protected

Dubious advice. Any subclass can now change a variable that perhaps relies upon it having certain constraints. Negative interest rates maybe are not allowed. You can initialize with super keyword instead and rely on accessor methods. If Account was abstract, that's a better argument for protected member variables maybe.