MODULE - 3 java
MODULE - 3 java
JAVA PROGRAMMING
• Simple interest program in Java | Simple interest is a quick and easy method of
calculating the interest charge on a loan. Simple interest is determined by multiplying
the daily interest rate by the principal by the number of days that elapse between
payments.
The formula for simple interest is given as,
Simple Interest = (principal amount × interest rate × time) / 100
❖ Procedures to write Simple interest program in Java
1) Define class and the main method
2) Declare variables for taking inputs:- principal amount, time, and interest rate
3) import Scanner class of util package to read inputs
4) Read inputs from end-user and store them in the declared variables
5) Calculate simple interest using the formula, and store it in a variable
6) Display the simple interest
7) Close the Scanner class object
// declare variables
double principalAmount = 0.0;
double rate = 0.0;
double time = 0.0;
double interest = 0.0;
// read inputs
System.out.print("Enter principal amount:: ");
principalAmount = scan.nextDouble();
System.out.print("Enter time (in months):: ");
time = scan.nextDouble();
System.out.print("Enter the interest rate (per year):: ");
rate = scan.nextDouble();
// calculate simpleInterest
interest = (principalAmount * rate * time) / 100;
// display result
System.out.println("Simple interest = "+interest);
System.out.println("Total amount to pay = "+
(principalAmount+interest));
// close scan
scan.close();
}
}
Output:-
Enter principal amount:: 10000
Enter time (in months):: 60
Enter the interest rate (per year):: 3.9
Simple interest = 23400.0
Total amount to pay = 33400.0
TASKS TO BE COMPLETED:
• Compound Interest Program in Java | Compound interest is calculated by
multiplying the initial principal amount by one plus the annual interest rate raised to
the number of compound periods minus one. After that, the total initial amount of the
loan is then subtracted from the resulting value.
• So, to calculate the annual compound interest, multiply the original amount of your
investment or loan, or principal, by the annual interest rate. Add that amount to the
principal, then multiply by the interest rate again to get the second year’s compounding
interest.
For this purpose, the formula of compound interest, including principal sum, is:-
A = P*(1 + r/n)^(n*t)
Where the meaning of these terms is:
A = the future value of the investment/loan, including interest
P = the principal investment amount (the initial deposit or loan amount)
r = the annual interest rate (decimal)
n = the number of times that interest is compounded per unit t
t = the time the money is invested or borrowed for
The above formula gives the total amount. To find the compound interest use,
“Compound Interest = A – P”