Моя задача: создать суперкласс Account и подкласс StudentAccount. Отличается учетная запись StudentAccount тем, что они получают бонус в размере 1 долл. США за депозит, но комиссию в размере 2 долл. США за вывод средств. Я переопределил методы суперкласса для методов в подклассе. Единственный метод, который, похоже, не работает, это мой метод вывода.
public class BankTester
{
public static void main(String[] args)
{
Account deez = new Account("Bob", 10.0);
Account jeez = new StudentAccount("Bobby", 10.0);
jeez.withdrawal(2.0);
System.out.println(jeez);
deez.withdrawal(2.0);
System.out.println(deez);
}
}
public class Account
{
private String name;
private double balance;
// Initialize values in constructor
public Account(String clientName, double openingBal){
name = clientName;
balance = openingBal;
}
// Complete the accessor method
public double getBalance(){
return balance;
}
// Add amount to balance
public void deposit(double amount){
balance += amount;
}
// Subtract amount from balance
public void withdrawal(double amount){
balance -= amount;
}
// Should read: Regular account with a balance of $__.__
public String toString(){
return "Regular account with a balance of $" + balance;
}
}
public class StudentAccount extends Account
{
// Complete this class with Override methods.
public StudentAccount(String studentName, double
openingBal){
super(studentName, openingBal);
}
// Students get a $1 bonus on depositing
@Override
public void deposit(double amount){
super.deposit(amount + 1);
}
// Students pay a $2 fee for withdrawing
@Override
public void withdrawal(double amount){
super.withdrawal(amount - 2);
}
// toString() Should read: Student account with a
balance of $__.__
@Override
public String toString(){
return "Student account with a balance of $" +
super.getBalance();
}
}