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

This needs to be written in Java... ChequingAccount class -logiv addBankAccount(

ID: 3724226 • Letter: T

Question

This needs to be written in Java...

ChequingAccount class -logiv addBankAccount()

ChequingAccount Class data members:

-->private double fee;

Method addBankAccount():

CALL super.addBankAccount()

READ valid fee from user

RETUEN true

Class ChequingAccount: This class w be inherited from BankAccount and contains the data members for a chequing account double fee) Methods (ie o toString): String - returns the data of the account formatted to display o addBankAccount): boolean - prompts user to enter data for this object from keyboard edits data, and doesn't allow user to continue with bad data o monthlyAccountUpdate) processes the object with monthly update of withdrawing the fee (as long as bank balance is morethan fee, else displays error message)

Explanation / Answer

ChequingAccount.java

import java.util.Scanner;

public class ChequingAccount extends BankAccount {
   private double fee;
   ChequingAccount(){
       fee =0;
       super.BankAccount();
   }
   //addBankaccount with input from user.
   void addBankAccount(){
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter the cust_no and balance: ");
       String cust_no = sc.nextLine();
       String pattern= "^[a-zA-Z0-9]*$";
while(!cust_no.matches(pattern)){
   System.out.println("Valid customer number are 6 characters and/or digits");
   System.out.println("Please re-enter valid Customer number: ");
   cust_no = sc.nextLine();
}
       double bal = sc .nextDouble();
       //Invoke addBankAccount of superClass
       super.addBankAccount(cust_no,bal);
       //Get Fee from user
       System.out.println("Enter the fee:");
       fee = sc.nextDouble();
       while(!(fee<bal)|| !(fee>0)){
           System.out.println("Invalid Fee");
           fee = sc.nextDouble();
       }
   }
   //monthlyAccountUpdate function which deducts the fee from the balance.
   boolean monthlyAccountUpdate(){
       if(bal>fee){
           bal = bal -fee;
           return true;
       }
       else{
           System.out.println("Insufficient Balance");
           return false;
       }
      
   }
   public String toString(){
       String str = "Customer_No = "+cust_no+" Balance ="+bal+" Fee ="+fee;
       return str;
      
   }
   public static void main(String[] args){
       ChequingAccount c = new ChequingAccount();
       c.addBankAccount();
       c.monthlyAccountUpdate();
       System.out.println(c.toString());
   }

}

BankAccount.java

//Super Class
public class BankAccount {
   String cust_no;
       double bal;

   void BankAccount()
       {
           bal = 0;
       }
//addBankAccount superclass
       void addBankAccount(String no,double b)
       {
           cust_no = no;
           bal = b;
       }

       public void deposit(double amt)
       {
           bal = bal + amt;
       }

       public void withdraw(double amt)
       {
           bal = bal - amt;
       }

       public double getBalance()
       {
           return bal;
       }


}

Output

Enter the cust_no and balance:
qwe123
1000
Enter the fee:
50
Customer_No = qwe123 Balance =950.0 Fee =50.0

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