In: Computer Science
Calculate Interest in a Java program.
If you know the balance and the annual percentage interest rate,
you can compute the interest on the next monthly payment
using the following formula: interest = balance *
(annualInterestRate/1200)
Write a program that reads the balance and the annual percentage
interest rate and
displays the interest for the next month.
Create a scanner
Prompt the user to enter a name and create variable for
scanner
Prompt the user to enter a balance and the annual percentage
interest rate
Create variable double balance for scanner
Create variable double annual for interest rate for scanner
Create variable double interest which is equal to annual for interest rate divided by 1200
Display result of balance
Here is the solution to above problem in Java. Please read the code comments for more information
JAVA CODE
import java.util.*;
public class Main
{
public static void main(String[] args) {
//create the Scanner variable
Scanner sc = new Scanner(System.in);
//Create variable to take input and result
double balance,annual,interest;
//prompt user for balance
System.out.print("Enter Balance:
");
balance = sc.nextDouble();
//prompt user for annual interest
rate
System.out.print("Annual Percentage
Interest Rate: ");
annual = sc.nextDouble();
//calculate the Interest
interest = balance
*(annual/1200);
System.out.println("Interest is: "
+ interest);
}
}