Question: Lab 3 Your task is to create simple deposit/credit calculator for… -Free Course Hero Question Answer.

Question Description: Lab 3 Your task is to create simple deposit/credit calculator for…

Image transcription text

Lab 3 Your task is to create simple deposit/credit calculator for different type of banks; Structure of your project is following: Package "Bank": Calculator.java, NationalBank.java, SecondTierBank.java; root of src folder: "main.java"; More in details about each java file: 1. main.java You are going to use your main class in order to test your application (creation of necessary objects, method invocation and so on) and to provide user with simple interaction via console (use "switch" to choose between options/invocation of certain methods with necessary parameters that you will get from scanner); 2. NationalBank.java Has fixed field fixedBankReward which is equal to 1% (think about how to make that field constant and about its data type); field is private; reward is given for deposits that longer than a year; Has reference to instance of Calculator object which is instantiated within the constructor of NationalBank class; field is private; Has method "calculateDeposit" which calculates deposit revenue for a different type of clients: "individual" and "legalEntity"; since we don’t have such objects for clients, think which data type to choose; method should be safe from overriding Method also gets amount of money, and duration in months as parameters; However, whole calculations proceed on Calculator object; Has method "calculateCredit" which calculates amount of credit return for a different type of clients: "individual" and "legalEntity"; since we don’t have such objects for clients, think which data type to choose; method could be overridden; Method also gets amount of money, and duration in months as parameters; However, whole calculations proceed on Calculator object; 3. SecondTierBank.java Class extends from NationalBank.java; Has fixed field fixedBankReward which is equal to 2% (think about how to make that field constant and about its data type); field is private; reward is given for deposits that longer than a year; Has fixed field fixedInterestRate which is equal to 3% (think about how to make that field constant and about its data type); field is private; field is used in calculation of credits; . Has reference to instance of Calculator object which is instantiated within the constructor of SecondTierBank class; field is private; Inherits method "calculateDeposit"; Inherits and overrides method "calculateCredit" which calculates amount of credit return for a different type of clients: "individual" and "legalEntity"; since we don’t have such objects for clients, think which data type to choose; Method also gets amount of money, and duration in months as parameters; However, whole calculations proceed on Calculator object then uses fixedInterestRate to return overall sum; 4. Calculator.java

Free Course Hero Answer

Course Hero Answer & Explanation:

Find below the classes

package Bank;

public class Calculator {

    private final double RATEFORINDIVIDUAL = 0.08;
    private final double RATEFORLEGALENTITIES = 0.10;

    public double depositReward(double amount, double durationInYears, ClientType clientType){
        switch (clientType){
            case INDIVIDUAL:
                return (amount * durationInYears * RATEFORINDIVIDUAL);
            case LEGAL_ENTITY:
                return (amount * durationInYears * RATEFORLEGALENTITIES);
            default: return 0;
        }
    }

    public double calculateCredit(double amount, double durationInYears, ClientType clientType){
        switch (clientType){
            case INDIVIDUAL:
                return (amount * durationInYears * RATEFORINDIVIDUAL);
            case LEGAL_ENTITY:
                return (amount * durationInYears * RATEFORLEGALENTITIES);
            default: return 0;
        }
    }

}
package Bank;

public class NationalBank {
    private final double FIXEDBANKREWARD = 0.01;
    public Calculator calculator;

    public NationalBank() {
        this.calculator = new Calculator();
    }

    public double calculateDeposit(double amount, double durationInMonths, ClientType clientType){
        return calculator.depositReward(amount, durationInMonths, clientType) * FIXEDBANKREWARD;
    }

    public double calculateCredit(double amount, double durationInMonths, ClientType clientType){
        return calculator.calculateCredit(amount, durationInMonths, clientType) * FIXEDBANKREWARD;
    }
}
package Bank;

public class SecondTierBank extends NationalBank{
    private final double FIXEDBANKREWARD = 0.02;
    private final double FIXEDINTERESTRATE = 0.03;

    public SecondTierBank() {
        super();
    }

    @Override
    public double calculateCredit(double amount, double durationInYears, ClientType clientType){
        return calculator.calculateCredit(amount, durationInYears, clientType) * FIXEDINTERESTRATE;
    }
}
package Bank;

import java.util.Scanner;

public class main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        //Take input as per requirement

        NationalBank nationalBank = new NationalBank();
        SecondTierBank secondTierBank = new SecondTierBank();
        System.out.println(nationalBank.calculateDeposit( 1000, 1, ClientType.INDIVIDUAL));
        System.out.println(nationalBank.calculateDeposit( 1000, 1, ClientType.LEGAL_ENTITY));
        System.out.println(secondTierBank.calculateDeposit( 1000, 1, ClientType.INDIVIDUAL));
        System.out.println(secondTierBank.calculateDeposit( 1000, 1, ClientType.LEGAL_ENTITY));

        System.out.println(nationalBank.calculateCredit( 1000, 1, ClientType.INDIVIDUAL));
        System.out.println(nationalBank.calculateCredit( 1000, 1, ClientType.LEGAL_ENTITY));
        System.out.println(secondTierBank.calculateCredit( 1000, 1, ClientType.INDIVIDUAL));
        System.out.println(secondTierBank.calculateCredit( 1000, 1, ClientType.LEGAL_ENTITY));
    }
}

You can change the logic of the calculator and use inputs as per your requirement.

Similar Posts