Question: JAVA Make the Account class as an abstract class. Define an abstract method printAccountInfo() which should be implemented by the sub classes. This method should
JAVA
Make the Account class as an abstract class. Define an abstract method printAccountInfo() which should be implemented by the sub classes. This method should display the type of account along with the account details.
public class Account { protected int accountNumber; protected double balance;
// Constructor public Account(int a) { balance = 0.0; accountNumber = a; }
public void deposit(double amount) { if (amount > 0) balance += amount; else System.err.println("Account.deposit(...): " + "cannot deposit negative amount."); }
public void withdraw(double amount) { if (amount > 0) if (balance - amount >= 0) balance -= amount; else System.err.println("Account.withdraw(...): " + "cannot withdraw more than your balance."); else System.err.println("Account.withdraw(...): " + "cannot withdraw negative amount."); }
public double getbalance() { return balance; }
public double getAccountNumber() { return accountNumber; }
public void display() { System.out.println("Account " + accountNumber + " : " + "Balance = " + balance); }
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
