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

BankingAccount Class code is: ? package BANKACCOUNTS; public class BankAccount {

ID: 3920415 • Letter: B

Question

BankingAccount Class code is: ?

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

}

}

Section B:

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

Class CheckingAccount has only one attribute:

checking balance, that is defined as private.

Class CheckingAccount 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 the attribute checking balance,

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,

checking balance (only 2 digits after decimal point)

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)

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.

Explanation / Answer


Given below is the code for the question.
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


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);
}
}


CheckingAccount.java
------------
package BANKACCOUNTS;

public class CheckingAccount extends BankAccount {
private double checkingBalance;

public CheckingAccount(){
super();
checkingBalance = 0;
accountType = "CHECKING";
}

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

public double getCheckingBalance() {
return checkingBalance;
}

public void setCheckingBalance(double checkingBalance) {
this.checkingBalance = checkingBalance;
}

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

}

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);
}

}


AccountDisplayer.java
--------------
package BANKACCOUNTS;

import java.util.Scanner;

public class AccountDisplayer {

public static void main(String[] args) {
long accountNum;
String custName;
double balance;
double interest;
int type;
Scanner keyboard = new Scanner(System.in);
BankAccount acc = null;

do{
System.out.println("1. Checking account");
System.out.println("2. Mortgage account");
System.out.println("Which type of account do you want?");
type = keyboard.nextInt();
System.out.println();
}while(!(type == 1 || type == 2));


if(type == 1)
acc = new CheckingAccount();
else
acc = new MortgageAccount();

System.out.print("Enter account number: ");
accountNum = keyboard.nextLong();

keyboard.nextLine();//get rid of newline char
System.out.print("Enter customer full name: ");
custName = keyboard.nextLine();

acc.setAccountNumber(accountNum);
acc.setCustomerName(custName);

if(type == 1){
System.out.print("Enter checking balance: ");
balance = keyboard.nextDouble();
((CheckingAccount)acc).setCheckingBalance(balance);
}
else{
System.out.print("Enter principal balance: ");
balance = keyboard.nextDouble();
((MortgageAccount)acc).setPrincipalBalance(balance);

System.out.print("Enter interest rate: ");
interest = keyboard.nextDouble();
((MortgageAccount)acc).setInterestRate(interest);
}

System.out.println("The accound details are as follows");
acc.displayAccountData();
}

}


output
-----
1. Checking account
2. Mortgage account
Which type of account do you want?
1

Enter account number: 12345
Enter customer full name: John Smith
Enter checking balance: 1000
The accound details are as follows
12345, CHECKING, John Smith, 1000.00


----
1. Checking account
2. Mortgage account
Which type of account do you want?
2

Enter account number: 56789
Enter customer full name: Bill Smith
Enter principal balance: 4000
Enter interest rate: 3.5
The accound details are as follows
56789, MORTGAGE, Bill Smith, 4000.00, 3.50

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