2.12* (Financial
application: calculating interest) 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 *
1annualInterestRate / 12002
Write a
program that reads the balance and the annual percentage interest rate and displays
the interest for the next month in two versions: (a) Use dialog boxes to obtain
input and display output; (b) Use console input and output.
Code : (a)
File name-CalculatingInterest2.java
import java.util.*;
import javax.swing.*;
public class
CalculatingInterest2 {
public static void main (String arg[]){
String balances
=JOptionPane.showInputDialog("Enter balance: ");
double
balance=Double.parseDouble(balances);
String airs
=JOptionPane.showInputDialog("Enter annual interest: ");
double air=Double.parseDouble(airs);
double interest=balance*(air/1200);
String output="The interest is : =
"+interest;
JOptionPane.showMessageDialog(null,
output);
}
}
Code
: (b) File name-CalculatingInterest.java
import
java.util.*;
import
javax.swing.*;
public
class CalculatingInterest {
public static void main (String arg[]){
Scanner input =new Scanner(System.in);
System.out.print("Enter balance: =
");
double balance = input.nextDouble();
System.out.print("Annual Iterest
Rate: = ");
double annualInterestRate =
input.nextDouble();
double
interest=(balance*(annualInterestRate/1200));
System.out.print("The interest is:
= "+interest);
}
}