Java Program to Calculate Simple Interest

Write a Java Program to Calculate Simple Interest with an example. The formula behind this Simple Interest calculation = (Principal Amount * Rate of Interest * Number of years) / 100

Java Program to Calculate Simple Interest Example

This Java program allows the user to enter the Principal Amount, total Number of years, and Interest Rate. Using those values, this program finds the simple Interest using the above-specified formula.

import java.util.Scanner;

public class SimpleInterest1 {

	private static Scanner sc;
	public static void main(String[] args) 
	{
		double PAmount, ROI, TimePeriod, simpleInterset;
		sc = new Scanner(System.in);
		
		System.out.print(" Please Enter the Principal Amount : ");
		PAmount = sc.nextDouble();
		
		System.out.print(" Please Enter the Rate Of Interest : ");
		ROI = sc.nextDouble();
		
		System.out.print(" Please Enter the Time Period in Years : ");
		TimePeriod = sc.nextDouble();
		
		simpleInterset = (PAmount * ROI * TimePeriod) / 100;
		
		System.out.println("\n The Simple Interest for Principal Amount " + PAmount + " is = " + simpleInterset);
	}
}
Java Program to Calculate Simple Interest 1

Java Program to Find Simple Interest using functions

This program is the same as above, but we are creating a different method to find the Simple Interest this time.

import java.util.Scanner;

public class ScI2 {
	private static Scanner sc;
	public static void main(String[] args) 
	{
		double PAmount, ROI, TimePeriod;
		sc = new Scanner(System.in);
		
		System.out.print(" Please Enter the Principal Amount : ");
		PAmount = sc.nextDouble();
		
		System.out.print(" Please Enter the Rate Of Interest : ");
		ROI = sc.nextDouble();
		
		System.out.print(" Please Enter the Time Period in Years : ");
		TimePeriod = sc.nextDouble();
		
		calSimpleIntr(PAmount, ROI, TimePeriod);
		
	}
	public static void calSimpleIntr(double PAmount, double ROI, double TimePeriod)
	{
		double SI;
		
		SI = (PAmount * ROI * TimePeriod) / 100;
		
		System.out.println("\n The Total Amount " + PAmount + " is = " + SI);
	}
}
Java Program to Calculate Simple Interest using functions

Instead of printing the Simple Interest from a method, this program returns a value. Next, we assign the return value to another variable within the main Java program.

import java.util.Scanner;

public class SimIn3 {

	private static Scanner sc;
	public static void main(String[] args) 
	{
		double PAmount, ROI, TimePeriod, SI;
		sc = new Scanner(System.in);
		
		System.out.print(" Please Enter the Principal Amount : ");
		PAmount = sc.nextDouble();
		
		System.out.print(" Please Enter the Rate Of Interest : ");
		ROI = sc.nextDouble();
		
		System.out.print(" Please Enter the Time Period in Years : ");
		TimePeriod = sc.nextDouble();
		
		SI =  calSimInt(PAmount, ROI, TimePeriod);
		System.out.println("\n The Simple Interest for Principal Amount " + PAmount + " is = " + SI);
		
	}
	public static double calSimInt(double PAmount, double ROI, double TimePeriod)
	{
		double SI;
		
		SI = (PAmount * ROI * TimePeriod) / 100;
		
		return SI;
	}
}
Java Program to Calculate Simple Interest 3

Comments are closed.