Question

In: Computer Science

Information. in java Consider a banking system with 3 classes:  BankAccount, CheckingAccount, and SavingsAccount, that you are...

Information. in java Consider a banking system with 3 classes:  BankAccount, CheckingAccount, and SavingsAccount, that you are to design and write. Have CheckingAccount and SavingsAccount inherit from BankAccount. In BankAccount, you should include an account number, an account balance, a deposit method, a toString method, and an abstract withdraw method. Since deposits work the same way in both child classes, make sure they cannot override it. The constructor should only take an initial deposit and generate a random 5 digit account number. The toString should display the account number and the balance.

In the CheckingAccount class add a minimum balance and a standard overdraft fee of $25. Implement the withdraw method so that overdrafts are allowed, but the overdraft fee is incurred if the balance drops below the minimum balance. Override the toString method to display everything the BankAccount toString displays plus the minimum balance. Use the parent class toString to do most of the work.

In the SavingsAccount class add an annual interest rate (with a default value of 1.5%) and a method to recalculate the balance every month. Since the interest rate is annual, make sure to calculate the interest accordingly. Override the toString method to display everything the BankAccount toString displays plus the interest rate. Like the CheckingAccount toString, you should use the parent class to do most of the work.

question. Write the Java implementation of the SavingsAccount. Note: no driver is required.

Solutions

Expert Solution

BankAccount.java

import java.util.Random;

public abstract class BankAccount {
        private int accountNumber;
        private double accountBalance;

        public BankAccount(double initialDeposit) {
                this.accountBalance = initialDeposit;
                Random rand = new Random();
                this.accountNumber = rand.nextInt(99999 - 10000 + 1) + 10000;
        }

        public int getAccountNumber() {
                return accountNumber;
        }

        public void setAccountNumber(int accountNumber) {
                this.accountNumber = accountNumber;
        }

        public double getAccountBalance() {
                return accountBalance;
        }

        public void setAccountBalance(double accountBalance) {
                this.accountBalance = accountBalance;
        }

        public final void deposit(double amount) {
                this.accountBalance = this.accountBalance + amount;
        }

        public abstract boolean withdraw(double amount);

        public String toString() {
                return "Account Number: " + this.accountNumber + ", Balance: "
                                + this.accountBalance;
        }
}

CheckingAccount.java

public class CheckingAccount extends BankAccount {
        private double minimumBalance;
        private static int OVERDRAFT_FEE = 25;

        public CheckingAccount(double initialDeposit, double minimum) {
                super(initialDeposit);
                this.minimumBalance = minimum;
        }

        @Override
        public boolean withdraw(double amount) {
                this.setAccountBalance(this.getAccountBalance() - amount);
                if (this.getAccountBalance() < minimumBalance) {
                        this.setAccountBalance(this.getAccountBalance() - OVERDRAFT_FEE);
                }
                return true;
        }

        public double getMinimumBalance() {
                return minimumBalance;
        }

        public void setMinimumBalance(double minimumBalance) {
                this.minimumBalance = minimumBalance;
        }

        public String toString() {
                return super.toString() + ", Minimum Balance: " + this.minimumBalance;
        }
}

SavingsAccount.java

public class SavingsAccount extends BankAccount {

        public double annualInterestRate;

        public SavingsAccount(double initialDeposit) {
                super(initialDeposit);
                this.annualInterestRate = 1.5;
        }

        public double getAnnualInterestRate() {
                return annualInterestRate;
        }

        public void setAnnualInterestRate(double annualInterestRate) {
                this.annualInterestRate = annualInterestRate;
        }

        @Override
        public boolean withdraw(double amount) {
                if ((this.getAccountBalance() - amount) < 0) {
                        return false;
                } else {
                        this.setAccountBalance(this.getAccountBalance() - amount);
                        return true;
                }
        }

        public void recalculateMonthlyBalance() {
                double monthlyInterest = this.getAccountBalance()
                                * (this.annualInterestRate / 1200.0);
                this.setAccountBalance(this.getAccountBalance() + monthlyInterest);
        }

        public String toString() {
                return super.toString() + ", Annual Interest Rate: "
                                + this.annualInterestRate;
        }

}

Related Solutions

Information: Consider a banking system with 3 classes:  BankAccount, CheckingAccount, and SavingsAccount, that you are to design...
Information: Consider a banking system with 3 classes:  BankAccount, CheckingAccount, and SavingsAccount, that you are to design and write. Have CheckingAccount and SavingsAccount inherit from BankAccount. In BankAccount, you should include an account number, an account balance, a deposit method, a toString method, and an abstract withdraw method. Since deposits work the same way in both child classes, make sure they cannot override it. The constructor should only take an initial deposit and generate a random 5 digit account number. The...
/* Work to do: 1) add toString method to BankAccount and SavingsAccount classes 2) Override the...
/* Work to do: 1) add toString method to BankAccount and SavingsAccount classes 2) Override the withdraw() in SavingsAccount so that it will not withdraw more money than is currently in the account. 3) Provide constructors for SavingsAccount 4) Add this feature to SavingsAccount: If you withdraw more than 3 times you are charged $10 fee and the fee is immediately withdrawn from your account.once a fee is deducted you get another 3 free withdrawals. 5) Implement the Comparable Interface...
JAVA LANGUAGE Required Tasks: In Eclipse, create a Java Project as CS-176L-Assign5. Create 3 Java Classes...
JAVA LANGUAGE Required Tasks: In Eclipse, create a Java Project as CS-176L-Assign5. Create 3 Java Classes each in its own file Student.java, StudentList.java, and Assign5Test.java. Copy your code from Assignment 4 into the Student.java and StudentList.java Classes. Assign5Test.java should contain the main method. Modify StudentList.java to use an ArrayList instead of an array. You can find the basics of ArrayList here: https://www.w3schools.com/java/java_arraylist.asp In StudentList.java, create two new public methods: The addStudent method should have one parameter of type Student and...
JAVA LANGUAGE Required Tasks: In Eclipse, create a Java Project as CS-176L-Assign4. Create 3 Java Classes...
JAVA LANGUAGE Required Tasks: In Eclipse, create a Java Project as CS-176L-Assign4. Create 3 Java Classes each in its own file Student.java, StudentList.java, and Assign4Test.java. Copy your code from Assignment 3 into the Student.java and StudentList.java. Assign4Test.java should contain the main method. In Student.java, add a new private variable of type Integer called graduationYear. In Student.java, create a new public setter method setGraduationYear to set the graduationYear. The method will have one parameter of type Integer. The method will set...
Lab 3 Java Classes and Memory Management Multi-file Project In this lab you will gain experience...
Lab 3 Java Classes and Memory Management Multi-file Project In this lab you will gain experience using classes and arrays of classes. Use the following as the beginning of a student abstract data type. public class Student { private String fName ; private String lName ; private double[] grades; } This class should be in the package com.csc241. Write a program that prompts a user for a total number of students and dynamically allocates memory for just that number of...
java program You are required to implement a Patient Information System for a clinic according to...
java program You are required to implement a Patient Information System for a clinic according to the following specifications: Class #1 PatientRecords (Tester class with main): This class contains a full list of patients (array list) and it provides the following functionalities: Add patient by ID-Number Print all records Print the number of patients based on specific attributes such as: disease name, gender. ***** See examples below for the input format (use console) Class #2 Patient: This class contains personal...
Required Tasks: In Eclipse, create a Java Project as CS-176L-Assign5. Create 3 Java Classes each in...
Required Tasks: In Eclipse, create a Java Project as CS-176L-Assign5. Create 3 Java Classes each in its own file Student.java, StudentList.java, and Assign5Test.java. Copy your code from Assignment 4 into the Student.java and StudentList.java Classes. Assign5Test.java should contain the main method. Modify StudentList.java to use an ArrayList instead of an array. You can find the basics of ArrayList here: https://www.w3schools.com/java/java_arraylist.asp In StudentList.java, create two new public methods: The addStudent method should have one parameter of type Student and should add...
Using Java Write only “stubs” for methods in the Figure, Rectangle, and Triangle classes: Consider a...
Using Java Write only “stubs” for methods in the Figure, Rectangle, and Triangle classes: Consider a graphics system that has classes for various figures — say, rectangles, boxes, triangles, circles, and so on. For example, a rectangle might have data members’ height, width, and either a center point or upper-left corner point, while a box and circle might have only a center point (or upper-right corner point) and an edge length or radius, respectively. In a well-designed system, these would...
explain The Structure of the Lebanese Banking System. not less than 3 paragraphs.
explain The Structure of the Lebanese Banking System. not less than 3 paragraphs.
JAVA Practice Exam 2 The project practice_exam_2 contains three (3) classes: Testing – This is the...
JAVA Practice Exam 2 The project practice_exam_2 contains three (3) classes: Testing – This is the file you will use to execute your program and test your cases. Each section refers to one or more specific array(s). From here, you can run the whole program or one section at a time. TestCases – This file contains all test cases. NO NEED FOR YOU TO PAY ATTENTION TO IT. YourCode – This is where you will be writing your code. Implement...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT