Bank Inheritance Program ISC Specimen 2023 Theory

A super class Bank has been defined to store the details of the customer in a bank. Define a subclass Interest to calculate the compound interest.

The details of the members of both the classes are given below:

Class name: Bank
Data members/instance variables:
name: to store the name of the customer
accNo: integer to store the account number
principal: to store the principal amount in decimals
Methods/member functions:
Bank(...): parameterized constructor to assign values to the data members
void display(): to display the customer details

Class name: Interest
Data members/instance variables:
rate: to store the interest rate in decimals
time: to store the time period in decimals
Methods/member functions:
Interest(...): parameterized constructor to assign values to the data members of both the classes
double calculate(): to calculate and return the compound interest using the formula:
CI = P(1 + R / 100)N - P, where P is the principal, R is the rate and N is the time
void display(): to display the customer details along with the compound interest

Assume that the super class Bank has been defined. Using the concept of inheritance, specify the class Interest giving details of the constructor, double calculate() and void display().

The super class, main() function and algorithm need not be written.

import java.util.Scanner;
class Bank{
    String name;
    int accNo;
    double principal;
    public Bank(String n, int a, double p){
        name = n;
        accNo = a;
        principal = p;
    }
    public void display(){
        System.out.println("Customer name: " + name);
        System.out.println("Account No. " + accNo);
        System.out.println("Principal amount: " + principal);
    }
}
class Interest extends Bank{
    double rate;
    double time;
    public Interest(String n, int a, double p, double r, double t){
        super(n, a, p);
        rate = r;
        time = t;
    }
    public double calculate(){
        return principal * Math.pow((1 + rate / 100), time) - principal;
    }
    public void display(){
        super.display();
        System.out.println("Rate: " + rate);
        System.out.println("Time: " + time);
        double ci = calculate();
        System.out.println("Compound Interest: " + ci);
    }
}
class Banking{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        System.out.print("Name of the customer: ");
        String n = in.nextLine();
        System.out.print("Account number: ");
        int a = Integer.parseInt(in.nextLine());
        System.out.print("Principal amount: ");
        double p = Double.parseDouble(in.nextLine());
        System.out.print("Rate of interest: ");
        double r = Double.parseDouble(in.nextLine());
        System.out.print("Time: ");
        double t = Double.parseDouble(in.nextLine());
        Interest obj = new Interest(n, a, p, r, t);
        obj.display();
    }
}

Comments

Popular posts from this blog

Encrypt Program ISC Specimen 2023 Theory

No Repeat Program ISC Computer Science 2022 Semester 2 Theory