This is an interactive Java program which accept Input from User using java.util.Scanner class. By the way calSI() method is used to calculate the simple interest. The formula to calculate Simple Interest is given below:
PROGRAM
simple_interest = (total_amount * rate * no_of_years) / 100
PROGRAM
import java.lang.*; // Import Language package import java.util.*; // Import Utility package to accept data class SimpleInterest { int amount; // data member declaration float rate; float years; double SI; SimpleInterest(int a, float r, float y) // Constructor to initialize data members { amount = a; rate = r; years = y; } void calSI() // method to calculate simple interest { SI = (amount*rate*years)/100; System.out.println("Simple Interest = "+SI); } public static void main(String args[]) { Scanner s = new Scanner(System.in); System.out.print("Enter Principal Amount :: "); int amt = s.nextInt(); // Converting string to int System.out.print("Enter Rate of Interest :: "); float rt = s.nextFloat(); System.out.print("Enter No. of years :: "); float yrs = s.nextFloat(); SimpleInterest e = new SimpleInterest(amt,rt,yrs); e.calSI(); } }OUTPUT
C:\>javac SimpleInterest.java C:\>java SimpleInterest Enter Principal Amount :: 3000 Enter Rate of Interest :: 5 Enter No. of years :: 4 Simple Interest = 600.0
No comments:
Post a comment