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

Section B: Define a Java class named “ CheckingAccount ” in the same package, BA

ID: 3920404 • Letter: S

Question

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)

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

}

}

Explanation / Answer

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

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