Question: Section D: Write a Java program that can read inputs of bank accounts and print out the account data. The account can be either a

Section D:

Write a Java program that can read inputs of bank accounts and print out the account data. The accountcan be either a checking account or a mortgage account.

First, the program reads an input of a numeric account code that identifies which type of account that the user wants to work with. The values of account code are:

1 for checking account

2 for mortgage account

The program should check to be sure that the user enters correct account code. Otherwise, the program asks the user to re-enter the code until it is correctly done.

Then, for the checking account, the user enters the following pieces of data from the console:

account number,

customer's full name,

checking balance (only 2 digits after decimal point)

For the mortgage account, the user enters the following pieces of data from the console:

account number,

customer's full name,

principal balance

interest rate

The program should check to be sure that checking balance, principal balance, and interest rate, are not negative.

The Java program is another Java class named AccountDisplayer in the same package, i.e.BANKACCOUNTS. To provide a solution to the problem, it is expected that inheritance and polymorphism are used in the coding.

The codes I have so far is:

BankAccounts.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);

}

}

CbeckingAccount.java ___________________________

package BANKACCOUNTS;

public class CheckingAccount extends BankAccount {

private int balance;

public CheckingAccount() {

}

public CheckingAccount(long accNumber, String name) {

accountNumber = accNumber;

customerName = name;

}

public int getBalance() {

return balance;

}

public void setBalance(int balance) {

this.balance = balance;

}

@Override

public void displayAccountData() {

System.out.println(accountNumber + ", " + accountType + ", " + customerName + ", " + String.format("%.2f", balance));

}

}

MortageAccount.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);

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!