Create an abstract class named Account for a bank. Include an int field for the
ID: 3653755 • Letter: C
Question
Create an abstract class named Account for a bank. Include an int field for the account number and a double field for the account balance. Create abstract accessors and mutators (getters and setters) for both fields. Remember: abstract methods don't have a body! Also include a constructor that requires an account number and that sets the balance to 0.0. Create two child classes of Account: Checking and Savings. Within the Checking class, the toString 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. Create an accessor and mutator for the interest rate field. The Savings toString 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. You are expected to use all rules that demonstrate compliance with naming conventions, constructors, instantiation, etc. Save your files as Account.java, Checking.java, Savings.java, and DemoAccounts.java.Explanation / Answer
public abstract class Book { String title = new String(); double price; public Book(String t) { title = t; } public String getTitle() { return title; } public double getPrice() { return price; } public abstract void setPrice(); } Fiction.java public class Fiction extends Book { public Fiction(String title) { super(title); setPrice(); } public void setPrice() { super.price=24.99; } } * NonFiction.java public class NonFiction extends Book { public NonFiction(String title) { super(title); setPrice(); } public void setPrice() { super.price=37.99; } } UseBook.java public class UseBook { public static void main(String[] args) { Fiction aNovel = new Fiction("Huckelberry Finn"); NonFiction aManual = new NonFiction("Elements of Style"); System.out.println("Fiction " + aNovel.getTitle() + " costs $" + aNovel.getPrice()); System.out.println("Non-Fiction " + aManual.getTitle() + " costs $" + aManual.getPrice()); } } Write a program named BookArray in which you create an array that holds 10 Books, some of which are Fiction and NonFiction. Use a for loop, display details about all 10 books. BookArray.java public class BookArray { public static void main(String[] args) { Book someBook[] = new Book[10]; int x; someBook[0] = new Fiction("Scarlet Letter"); someBook[1] = new NonFiction("Introduction to Java"); someBook[2] = new Fiction("Mill on the Floss"); someBook[3] = new NonFiction("The Road Not Taken"); someBook[4] = new Fiction("A Tale of Two Cities"); someBook[5] = new NonFiction("Europe on $5 a Day"); someBook[6] = new Fiction("War and Peace"); someBook[7] = new Fiction("A Simple Plan"); someBook[8] = new Fiction("Disclosure"); someBook[9] = new Fiction("Nancy Drew"); for(x = 0; xRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.