Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Section C: Define a Java class named “ MortgageAccount ” in the same package, BA

ID: 3920405 • Letter: S

Question

Section C:

Define a Java class named “MortgageAccount” in the same package, BANKACCOUNTS, that extends the above class BankAccount.

Class MortgageAccount has two attributes:

principal balance that is defined as private.

interest rate that is defined as private.

Class MortgageAccount definition provides:

a default constructor,

another constructor that accepts account number and customer's full name as two different parameters

get-method and set-method for eachvariable attribute

a public method (displayAccountData()) that overrides the method of the same name of the superclass BankAccount and prints out the following pieces of data in only one line:

account number,

account type,

customer's full name,

the principal balance (only 2 digits after decimal point),

the interest rate (only 2 digits after decimal point)

Explanation / Answer

Given below is the code for the question. I have also provide BankAccount class since you have not given here and it is needed by Mortgage Account
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
Please do rate the answer if it was helpful. Thank you


MortgageAccount.java
------------
package BANKACCOUNTS;

public class MortgageAccount extends BankAccount {
private double principalBalance;
private double interestRate;

public MortgageAccount(){
super();
accountType = "MORTGAGE";
}

public MortgageAccount(long accountNum, String custName){
super();
accountNumber = accountNum;
customerName = custName;
accountType = "MORTGAGE";
}

public double getPrincipalBalance() {
return principalBalance;
}

public void setPrincipalBalance(double principalBalance) {
this.principalBalance = principalBalance;
}

public double getInterestRate() {
return interestRate;
}

public void setInterestRate(double interestRate) {
this.interestRate = interestRate;
}

@Override
public void displayAccountData() {
System.out.printf("%d, %s, %s, %.2f, %.2f ", accountNumber, accountType, customerName, principalBalance, interestRate);
}

}

==========
BankAccount.java
----------
package BANKACCOUNTS;

public class BankAccount {
protected long accountNumber;
protected String accountType;
protected String customerName;

public BankAccount(){
accountNumber = 0;
accountType = "";
customerName = "";
}

public long getAccountNumber() {
return accountNumber;
}

public void setAccountNumber(long accountNumber) {
this.accountNumber = accountNumber;
}

public String getAccountType() {
return accountType;
}

public void setAccountType(String accountType) {
this.accountType = accountType;
}

public String getCustomerName() {
return customerName;
}

public void setCustomerName(String customerName) {
this.customerName = customerName;
}

public void displayAccountData(){
System.out.println(accountNumber + ", " + accountType + ", " + customerName);
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote