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...
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...
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...
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...
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.
Consider the following randomly arranged in 3 classes data of a sample. Classes frequency 5-9 9...
Consider the following randomly arranged in 3 classes data of a sample. Classes frequency 5-9 9 10-14 25 15-19 8 Plot the cumulative histogram and the polygon and interpret. (2.5+2.5+2.5=7.5) Determine the Range (5) Determine the mean and the median. (7.5+7.5=15) Determine the standard deviation. (7.5) Determine the relative frequency and determine the percentage of observation having a value equal or lower than 12. (5+2.5)
This program focuses on programming with Java Collections classes. You will implement a module that finds...
This program focuses on programming with Java Collections classes. You will implement a module that finds a simplified Levenshtein distance between two words represented by strings. Your program will need support files LevenDistanceFinder.Java, dictionary.txt, while you will be implementing your code in the LevenDistanceFinder.java file. INSTRUCTIONS The Levenshtein distance, named for it's creator Vladimir Levenshtein, is a measure of the distance between two words. The edit distance between two strings is the minimum number of operations that are needed to...
*JAVA* For this assignment you have been given two classes, a Main.java and a Coin.java. The...
*JAVA* For this assignment you have been given two classes, a Main.java and a Coin.java. The coin class represents a coin. Any object made from it will have a 1) name, 2) weight and 3) value. As of now, the instance variables in Coin.java are all public, and the main function is calling these variables directly for the one coin made in it. Your goal is to enforce information hiding principles in this project. Take Coin.java, make all instance variables...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT