Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Good evening, I was wondering if anybody would help me with a Java code.Thank you for the help in advance. The following are the steps:

Good evening, I was wondering if anybody would help me with a Java code.Thank you for the help in advance.

The following are the steps:

1)Now, take the code and modify it to include two new subclasses: CertificateOfDeposit (which is similar to the SavingsAccount class), and Mortgage (which is similar to the CheckingAccount class).

For the CertificateofDeposit class: assume an initial balance of 150,000, and an additional deposit of 50,000 upon renewal of the savings product.

For the Mortgage class: assume an initial balance of 250,000, and a payment of 50,000 to reduce the mortgage.

Place the modified code and a snapshot of the output in the lab template form.

2) Make the CertificateOfDeposit class a subclass of the SavingsAccount class. [Hint: you might need to overload the constructor of the SavingsAccount class]. Place the modified code and a snapshot of the output in the lab template form for this assignment.

So I started on the first part of number one by making the savingsAccount class and the CertificateOfDeposit class, I just need the rest.

Here is the code I am working with:

class Account { private String name;

private long amount;

Account(String name, long amount) { this.name = name; setAmount(amount); }

void deposit(long amount) { this.amount += amount; }

String getName() { return name; }

long getAmount() { return amount; }

void setAmount(long amount) { this.amount = amount; } } class SavingsAccount extends Account { SavingsAccount(long amount) { super("savings", amount); } }

class CheckingAccount extends Account { CheckingAccount(long amount) { super("checking", amount); }

void withdraw(long amount) { setAmount(getAmount() - amount); } } //add certificate of Deposit subclass class CertificateofDeposit extends Account { CertificateofDeposit(long amount) { super("Certificate of Deposit", amount); } } //add mortgage subclass of Account class Mortgage extends Account { Mortgage(long amount) { super("Mortgage", amount); }

void withdraw(long amount) { setAmount(getAmount() - amount); } } //class to execute main class AccountDemo { public static void main(String[] args) { //info on saving account SavingsAccount sa = new SavingsAccount(10000); System.out.println("account name: " + sa.getName()); System.out.println("initial amount: " + sa.getAmount()); sa.deposit(5000); System.out.println("new amount after deposit: " + sa.getAmount());

System.out.println(""); //info on checking account CheckingAccount ca = new CheckingAccount(20000); System.out.println("account name: " + ca.getName()); System.out.println("initial amount: " + ca.getAmount()); ca.deposit(6000); System.out.println("new amount after deposit: " + ca.getAmount()); ca.withdraw(3000); System.out.println("new amount after withdrawal: " + ca.getAmount()); System.out.println(""); //add certificate of deposit System.out.println(""); //add mortgage information } }

If it helps the following is the output before the added and new subclasses.

image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2022 Grenoble France September 19 23 2022 Proceedings Part 4 Lnai 13716

Authors: Massih-Reza Amini ,Stephane Canu ,Asja Fischer ,Tias Guns ,Petra Kralj Novak ,Grigorios Tsoumakas

1st Edition

3031264118, 978-3031264115

More Books

Students also viewed these Databases questions