Create an abstract class named Account for a bank. Include an integer field for
ID: 3622845 • Letter: C
Question
Create an abstract class named Account for a bank. Include an integer field for the account number and a double field for the account balance. Also include a constructor that requires an account number and that sets the balance to 0.0. Include a set method for the balance. Also include two abstract display methods--one for each field. Create two child classes of Account: Checking and Savings. Within the Checking class, the display method displays the String "Checking Account Information", the account number, and the balance. Within the Savings class, add a field to hold the interest rate and require the Savings constructor to accept an argument for the value of the interest rate. The Savings display method displays the String "Savings Account Information", the account number, the balance, and the interest rate. Write an application that demonstrates you can instantiate and display both Checking and Savings objects. Save your files as Account.java, Checking.java, Savings.java, and DemoAccounts.java.Explanation / Answer
Most of the solution is in the question. I won't do it all for you, but for (a): public abstract class Account { private int accountNumber; private double balance; public Account( int accNumber ) { accountNumber = accNumber; balance = 0.0; } public void setBalance( double newBalance ) { balance = newBalance; } public int getAccountNumber(); // the abstract get method for the account balance // how do you think you'd declare the get method for the balance? } public class Checking extends Account { public int getAccoutNumber() { System.out.println( "Checking Account Information" ); System.out.println( "" + accountNumber ); System.out.println( "" + balance ); }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.