Java Programming | Calculating simple interest.

Introduction

This is a tutorial for calculating simple interest in java. The program is given below that take inputs and calculates the simple interest and prints it. The program is not extendable. Go enjoy the program. Lets begin……….

Program for calculating simple interest in java.

//import Scanner as we require it.
import java.util.Scanner;

// the name of our class its public
public class SimpleInterest {
	//void main
		public static void main (String[] args)
		{
			//declare float
			float a,y,r,si,t;
			//define scanner
			Scanner input = new Scanner(System.in);

			//print message and take input.
			System.out.println("Enter Amount:");
			 a = input.nextFloat();

			 System.out.println("Enter Years");
			 y = input.nextInt();

			 System.out.println("Enter Rate of interest");
		     r = input.nextFloat();

		     //calculate
		     si=a*y*r/100;
		     t=a+si;

		     //print the output
			System.out.println("Simple interest = "+si);
			System.out.println("Total = " + t);
		}
}

Output

Enter Amount:
1000
Enter Years
2
Enter Rate of interest
3
Simple interest = 60.0
Total = 1060.0

How it works

  1. The program prints the message to enter necessary inputs.
  2. The user enters inputs.
  3. Simple interest and total is calculated
  4. The SI and Total  is printed.

Extending it

The program cannot be extended. There are no direction in which you can extend. So you cannot extend the program.

Explanation.

  1. Import the Scanner.
  2. Declare the class as public
  3. Add the void main function
  4. Add system.out.println() function with the message to enter necessary inputs.
  5. Declare input as Scanner.
  6. Take the inputs and save it in variables.
  7. Calculate Si and Total and save it in other variable.
  8. Add system.out.println() function to print the calculated Si and Total.

At the end.

You learnt creating the Java program for Calculating Simple Interest. So now enjoy the program.

Please comment on the post and share it.
And like it if you liked.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s