5

Java Program to Calculate & Display Simple Interest and Amount

Q: Giving that interest (I) = Principal * Rate * Time where Rate is decimal. Write a simple Java program will calculate and display the interest where the rate is 4.5 but time and principal must be collected through the keyboard. Display the interest and the amount where amount = Principal * Interest.

Solution

//A program to calculate simple interest and amount
import java.util.Scanner;

class interest
{
    public static void main(String arg[])
    {
        Scanner get_data = new Scanner(System.in);

        //Declaring variables
        double interest, rate, time, amount, principal;
        rate = 4.5;//initializing rate

        //Collecting data
        System.out.println("Enter principal: ");
        principal = get_data.nextDouble();
        System.out.println("Enter time: ");
        time = get_data.nextDouble();

        //Calculating
        interest = principal * rate * time;
        amount = principal + interest;

        //Outputting data
        System.out.println("Interest: " + interest + " Amount: " + amount);
    }
}