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

Due: See Programming Assignment 4 link on Canvas The purpose of this programming

ID: 3879025 • Letter: D

Question

Due: See Programming Assignment 4 link on Canvas The purpose of this programming project is to demonstrate a fundamental understanding of inheritance polymorphism, and interfaces REQUIREMENTS You will submit all source code files (4 in all) as a single zipped file named "Programming4.zip" through the Programming Assignment 4 Submission link on Canvas Not only will you be graded on program correctness (Program executes correctly, proper use of methods classes, inheritance, etc.) but also, good programming documentation techniques including javadoc, proper indentation, correct locations of braces, meaningful identifier names, preface instance fields with my and method parameter names with the, javadoc prior to methods, specific comments on complex code, etc. DETAILS You will create 3 classes related to banking operations for customers, and an Interface that is implemented by all either directly or inherited. Keep in mind, one major purpose of inheritance is to eliminate redundant code. For this reason you should take full advantage of super class code or methods when developing your subclasses You will create a basic bank account class "BankAccount.java," a more specific savings account class "SavingsAccount.java," an Interface for accessing and changing a customer's name "NamedAccount.java," a safe deposit box account class for establishing a safe deposit box “SafeDepositBoxAccount.java" which implements the NamedAccount interface, and finally, you will create toString() methods for your classes and modify the BankAccount class to also implement the NamedAccount interface. Always remember to use final constants in place of any literal constants, sometimes known as "Magic Numbers," (anything other than 0, 1, 2, & -1) you would normally use in your code! Greater detail of each class follows

Explanation / Answer

Hello, I have a solution for you. Implemented everything as per the requirements. Defined following things in this answer.

//BankAccount.java

public class BankAccount implements NamedAccount {

      /**

      * constant required while calculating the interest amount

      */

      private final double MONTHS = 12.0;

      /**

      * Required variables

      */

      private String customerName;

      private double balance;

      private double interestRate;

      protected int myMonthlyWithdrawCount;

      protected double myMonthlyServiceCharges;

      /**

      * Constructor to initialize a BankAccount

      *

      * @param theNameOfOwner

      *            - account holder name

      * @param theInterestRate

      *            - interest rate

      */

      public BankAccount(final String theNameOfOwner, final double theInterestRate) {

            customerName = theNameOfOwner;

            if (theInterestRate >= 0) {

                  interestRate = theInterestRate/100;

            } else {

                  /**

                  * in case of negative interest rate input, assigns 0

                  */

                  interestRate = 0;

            }

            balance = 0;

            myMonthlyWithdrawCount = 0;

            myMonthlyServiceCharges = 0;

      }

      /**

      *

      * @return the balance left

      */

      public double getBalance() {

            return balance;

      }

      /**

      * method to make a deposit

      */

      public boolean processDeposit(final double theAmount) {

            if (theAmount > 0) {

                  balance += theAmount;

                  return true;

            } else {

                  /**

                  * negative deposit is not possible

                  */

                  return false;

            }

      }

      /**

      * method to make a withdrawal

      */

      public boolean processWithdrawal(final double theAmount) {

            if (theAmount < 0 || theAmount > balance) {

                  /**

                  * amount can't be negative or greater than the available balance

                  */

                  return false;

            } else {

                  balance -= theAmount;

                  /**

                  * incrementing the withdrawal count

                  */

                  myMonthlyWithdrawCount++;

                  return true;

            }

      }

      /**

      * method to calculate and return the interest amount

      */

      public double calculateInterest() {

            /**

            * interest amount= balance * interest rate / 12.0

            */

            double monthlyRate = interestRate / MONTHS;

            return balance * monthlyRate;

      }

      /**

      * method to perform monthly processing

      */

      public void performMonthlyProcess() {

            /**

            * deducing service charges

            */

            balance -= myMonthlyServiceCharges;

            /**

            * Adding interest amount

            */

            balance += calculateInterest();

            /**

            * Resetting withdrawal count and service charges

            */

            myMonthlyWithdrawCount = 0;

            myMonthlyServiceCharges = 0;

            /**

            * if balance is less than 0, making it 0 (balance cant be negative)

            */

            if (balance < 0) {

                  balance = 0;

            }

      }

      /**

      * implemented methods to get and set account holder name

      *

      * @return

      */

      public String getAccountHolderName() {

            return customerName;

      }

      public void setAccountHolderName(String theNewName) {

            customerName = theNewName;

      }

      /**

      * method to return a string containing all data

      */

      public String toString() {

            return String.format("BankAccount[Owner: %s, Balance: %.2f,"

                        + " Interest Rate: %.2f, Monthly Withdrawals: %d, "

                        + "Monthly Service Charges: %.2f]", customerName, balance,

                        interestRate, myMonthlyWithdrawCount, myMonthlyServiceCharges);

      }

}

//SavingsAccount.java

public class SavingsAccount extends BankAccount {

      private boolean active;

      /**

      * constant for minimum balance

      */

      private final double MIN_BAL = 25.0;

      public SavingsAccount(String theNameOfOwner, double theInterestRate) {

            /**

            * Passing values to super class constructor

            */

            super(theNameOfOwner, theInterestRate);

            active = false; /*

                                    * Account should remain inactive unless $25 balance is

                                    * maintained

                                    */

      }

      @Override

      public boolean processDeposit(double theAmount) {

            /**

            * if super class processDeposit method returns true, means a successful

            * deposit. so in case of successful deposit, if balance is above $25,

            * account should be active

            */

            if (super.processDeposit(theAmount)) {

                  if (getBalance() >= MIN_BAL) {

                        active = true;

                  }

                  return true;

            }

            return false;

      }

      @Override

      public boolean processWithdrawal(double theAmount) {

            if (super.processWithdrawal(theAmount)) {

                  if (getBalance() < MIN_BAL) {

                        /**

                        * if current balance is less than minimum balance, account

                        * should be inactive

                        */

                        active = false;

                  }

                  if (myMonthlyWithdrawCount >= 5) {

                        /**

                        * starting from 5th withdrawal in a month, service charge of $1

                        * is applicable for any subsequent withdrawals

                        */

                        myMonthlyServiceCharges += 1;

                  }

                  return true;

            }

            return false;

      }

      @Override

      public void performMonthlyProcess() {

            super.performMonthlyProcess();

            /**

            * after monthly processing, if balance is less than the minimum,

            * account should be inactive

            */

            if (getBalance() < MIN_BAL) {

                  active = false;

            } else {

                  active = true;

            }

      }

      public String toString() {

           

            String str=super.toString();

            /**

            * making some changes to the super class String returned,

            * to minimize code redundancy and to maintain code integrity

            */

            str=str.replace("BankAccount", "SavingsAccount");

            str=str.substring(0, str.length()-1);

            return str + ", isActive: " + active+"]";

      }

}

//NamedAccount.java interface

public interface NamedAccount {

      String getAccountHolderName();

      void setAccountHolderName(final String theNewName);

}

//SafeDepositAccount.java class

public class SafeDepositBoxAccount implements NamedAccount {

      private String nameOfHolder;

      /**

      * implemented methods to get and set the name of holder

      */

      public String getAccountHolderName() {

            return nameOfHolder;

      }

      public void setAccountHolderName(String theNewName) {

            nameOfHolder = theNewName;

      }

      @Override

      public String toString() {

            return "SafeDepositBoxAccount Name of Holder: " + nameOfHolder;

      }

}

//AccountTester.java

public class AccountTester {

      public static void main(String[] args) {

            /**

            * Creating some test BankAccount objects

            */

            System.out.println("Creating a bank account for John Doe at 5.00 %");

            BankAccount account1=new BankAccount("John Doe", 5.0);

            System.out.println(account1);

            System.out.println("Creating a bank account for Sam Smith at -5.00 %");

            BankAccount account2=new BankAccount("Sam Smith", -5.0);

            System.out.println(account2);

            System.out.println("Changing account 1's owner name from John Doe to Jane Doe");

            account1.setAccountHolderName("Jane Doe");

            System.out.println(account1);

            /**

            * Testing SavingsAccount class

            */

            System.out.println("Creating a savings account for Dan Doe at 5.00 %");

            SavingsAccount savingsAccount1=new SavingsAccount("Dan Doe", 5.0);

            System.out.println(savingsAccount1);

            System.out.println("Depositing $100, account should be active now");

            savingsAccount1.processDeposit(100);

            System.out.println(savingsAccount1);

            System.out.println("making 5 withdrawals of $15 each");

            savingsAccount1.processWithdrawal(15);

            savingsAccount1.processWithdrawal(15);

            savingsAccount1.processWithdrawal(15);

            savingsAccount1.processWithdrawal(15);

            savingsAccount1.processWithdrawal(15);

            System.out.println(savingsAccount1);

            System.out.println("performing Monthly Processing");

            savingsAccount1.performMonthlyProcess();

            System.out.println(savingsAccount1);

      }

}

/*OUTPUT*/

Creating a bank account for John Doe at 5.00 %

BankAccount[Owner: John Doe, Balance: 0.00, Interest Rate: 0.05, Monthly Withdrawals: 0, Monthly Service Charges: 0.00]

Creating a bank account for Sam Smith at -5.00 %

BankAccount[Owner: Sam Smith, Balance: 0.00, Interest Rate: 0.00, Monthly Withdrawals: 0, Monthly Service Charges: 0.00]

Changing account 1's owner name from John Doe to Jane Doe

BankAccount[Owner: Jane Doe, Balance: 0.00, Interest Rate: 0.05, Monthly Withdrawals: 0, Monthly Service Charges: 0.00]

Creating a savings account for Dan Doe at 5.00 %

SavingsAccount[Owner: Dan Doe, Balance: 0.00, Interest Rate: 0.05, Monthly Withdrawals: 0, Monthly Service Charges: 0.00, isActive: false]

Depositing $100, account should be active now

SavingsAccount[Owner: Dan Doe, Balance: 100.00, Interest Rate: 0.05, Monthly Withdrawals: 0, Monthly Service Charges: 0.00, isActive: true]

making 5 withdrawals of $15 each

SavingsAccount[Owner: Dan Doe, Balance: 25.00, Interest Rate: 0.05, Monthly Withdrawals: 5, Monthly Service Charges: 1.00, isActive: true]

performing Monthly Processing

SavingsAccount[Owner: Dan Doe, Balance: 24.10, Interest Rate: 0.05, Monthly Withdrawals: 0, Monthly Service Charges: 0.00, isActive: false]

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