Knowee
Questions
Features
Study Tools

Write a java program to perform the concept of method overriding for calculating simple interest of 3 banks A,B,C., Bank A’s rate of interest-10%, Bank’s B rate of interest-9%, Bank’C rate of interest -7%.

Question

Write a java program to perform the concept of method overriding for calculating simple interest of 3 banks A,B,C., Bank A’s rate of interest-10%, Bank’s B rate of interest-9%, Bank’C rate of interest -7%.

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a simple Java program that demonstrates the concept of method overriding for calculating simple interest for 3 banks A, B, and C.

// Define a base class Bank
public class Bank {
    double rateOfInterest;
    
    double calculateInterest(double principal, double time) {
        return (principal * rateOfInterest * time) / 100;
    }
}

// Define a class BankA that extends Bank
public class BankA extends Bank {
    BankA() {
        rateOfInterest = 10.0;
    }
}

// Define a class BankB that extends Bank
public class BankB extends Bank {
    BankB() {
        rateOfInterest = 9.0;
    }
}

// Define a class BankC that extends Bank
public class BankC extends Bank {
    BankC() {
        rateOfInterest = 7.0;
    }
}

// Define a main class to test the program
public class Main {
    public static void main(String[] args) {
        double principal = 1000.0;
        double time = 2.0;

        BankA bankA = new BankA();
        System.out.println("Interest in Bank A: " + bankA.calculateInterest(principal, time));

        BankB bankB = new BankB();
        System.out.println("Interest in Bank B: " + bankB.calculateInterest(principal, time));

        BankC bankC = new BankC();
        System.out.println("Interest in Bank C: " + bankC.calculateInterest(principal, time));
    }
}

In this program, we have a base class Bank that has a method calculateInterest() for calculating the simple interest. This method is overridden in the derived classes BankA, BankB, and BankC by setting different values for the rateOfInterest in their constructors. The Main class creates objects of BankA, BankB, and BankC and calls their calculateInterest() method to calculate and print the interest.

This problem has been solved

Similar Questions

Write a program in Java using a method Discount( ), to calculate a single discount or a successive discount. Use overload methods Discount(int), Discount(int,int) and Discount(int,int,int) to calculate single discount and successive discount respectively. Calculate and display the amount to be paid by the customer after getting discounts on the printed price of an article.

Program on Polymorphism: Implement a Program to demonstrate method overriding A boy has his money deposited $1000, $1500, and $2000 in banks-Bank A, Bank B and Bank C respectively. We have to print the money deposited by him in a particular bank.Create a class 'Bank' with a method 'getBalance' which returns 0. Make its three subclasses named 'BankA', 'BankB' and 'BankC' with a method with the same name 'getBalance' which returns the amount deposited in that particular bank. Call the method 'getBalance' by the object of each of the three bankswrite a java code and its explaination

Write the pseudocodes/algorithm for the given questions.a. ABC bank offers 5% discount if payment is made within 10 days after notice. No discount ifthe payment is made after 10 days.b. A program receives input of an integer number. This number is then to be multiplied bynumbers from 1 to 12. The result for each multiplication is printe

Mr. Agarwal invests certain sum at 5% per annum compound interest for three years. Write a program in Java to calculate: (a) the interest for the first year (b) the interest for the second year (c) the amount after three years. Take sum as an input from the user. Sample Input: Principal = ₹5000, Rate =10%, Time = 3 yrs Sample Output: Interest for the first year: ₹500 Interest for the second year: ₹550 Interest for the third year: ₹605

Create an abstract class Bank with an abstract method getRateOfInterest();    In class SBI calculate the interest amount as 5% of the principal by overriding the method getRateOfInterest(); and display. In the class PNB  calculate the interest amount as 6% of the principal by overriding the method getRateOfInterest(); and display

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.