#Issues with setting up class
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
where are the field variables for id/balanche/overdraft?
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
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;
}
Detected code, here are some useful tools:
class Account {
private int id;
private double balance;
private static double annualInterestRate;
private Date dateCreated;
they are private
as said make them protected
so why is overdraft still an issue. is it because i havent initialized it as a variable in the subclass?
yep that fixed it
yeah
alright thank you!
oh sheesh we got emotes now
?
yeah updated that
noice
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.