Posted on by Kalkicode
Code Mathematics

Calculate simple interest

The problem at hand is about calculating simple interest using a given formula. Simple interest is a straightforward method of calculating the interest on a loan or an investment, where the interest is calculated only on the initial amount (the principal) that was invested or borrowed. The formula to calculate simple interest is:

Simple Interest (SI) = (Principal × Rate × Time) / 100


  • Principal: The initial amount of money invested or borrowed.
  • Rate: The annual interest rate as a percentage.
  • Time: The time in years for which the interest is calculated.

Problem Statement and Explanation

The goal is to create a Java program that takes three parameters - principal, time, and rate - and calculates the simple interest using the provided formula. The program should display the principal, time, rate, and the calculated simple interest.


Let's take an example to understand the problem better. Suppose someone invests $1500 at an annual interest rate of 7.3% for 3 years. The simple interest can be calculated as follows:

Principal = $1500 Time = 3 years Rate = 7.3%

Using the formula, we can calculate the simple interest: SI = (1500 × 3 × 7.3) / 100 = $328.5

Idea to Solve

To solve this problem, we can follow these steps:

  1. Create a class named "Interest."
  2. Define a method called "simpleInterest" that takes three parameters: principal, time, and rate.
  3. Inside the method, calculate the simple interest using the provided formula.
  4. Display the principal, time, rate, and calculated simple interest.
  5. In the "main" method, call the "simpleInterest" method with different test cases.


class Interest
    method simpleInterest(principal, time, rate)
        display "Principal : " + principal
        display "Time : " + time
        display "Rate : " + rate
        amount = (principal × time × rate) / 100
        display "Simple Interest : " + amount

    method main()
        call simpleInterest(1500, 3, 7.3)
        call simpleInterest(170.4, 7, 3.4)

Algorithm Explanation

  1. The program defines a class named "Interest."
  2. Inside the class, the "simpleInterest" method takes three parameters: principal, time, and rate.
  3. It displays the provided values of principal, time, and rate.
  4. It calculates the amount using the formula and displays the calculated simple interest.
  5. In the "main" method, the program calls the "simpleInterest" method with two different test cases.

Program List

Before you see the actual code, you write a function that takes three parameters (time, principle, and rate) and returns or displays the result.

Time Complexity

The time complexity of this program is constant (O(1)), as the number of operations performed remains the same regardless of the input values. The program performs a fixed set of calculations and display operations for each test case, so the time taken doesn't depend on the input size.


Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment