Java program to compute simple interest on the principal amount.
Problem Statement
Write a Java program to compute simple interest on the given principal amount. In this tutorial, we will write a simple java program to compute the simple interest amount.
Before writing the program, we would analyze the IPO(Input-Process-Output) of the program as given below.
IPO chart
Input to the Program:
- P = principal Amount
- R = Rate per annum
- T = Time (years)
Process
Simple Interest = P * T * R 100
Eclipse IDE Setup
Some steps and instructions to create a Java application on Eclipse IDE:
- Create Java Project in Eclipse
https://www.testingdocs.com/create-a-new-java-project-in-eclipse/
- Create Java Package in Eclipse
https://www.testingdocs.com/create-java-package-in-eclipse-ide/
- Create Java Class in Eclipse
https://www.testingdocs.com/create-a-new-java-class-in-a-project/
- Run Java Project in Eclipse
https://www.testingdocs.com/run-java-project-in-eclipse/
Java Program
package com.testingdocs.simple; import java.util.Scanner; /************************************************** * SimpleInterest.java * @program : * @web : www.TestingDocs.com * @author : * @version : 1.0 **************************************************/ public class SimpleInterest { public static void main(String[] args) { Scanner input = new Scanner(System.in); // Variables used double principal, rateOfInterest , timeInYears; double simpleInterest; // Prompt user for input System.out.println("Enter principal amount:= "); principal = input.nextDouble(); System.out.println("Enter rate of interest:= "); rateOfInterest= input.nextDouble(); System.out.println("Enter time duration in years := "); timeInYears = input.nextDouble(); //Calculation simpleInterest = ( principal * rateOfInterest * timeInYears )/100; //Output System.out.println("Simple Interest = " + simpleInterest); } }
Screenshot
—
Java Tutorial
Java Tutorial on this website:
https://www.testingdocs.com/java-tutorial/
More information on Java can be found on the official website: