Ask Question
13 December, 08:48

Write a well-commented Java program that answers the following questions in complete sentences such that the reader does not have to know the question in advance. Use either System. out methods or JOptionPane for your program output:

+3
Answers (1)
  1. 13 December, 09:10
    0
    import java. util. Scanner;

    import javax. swing. JOptionPane;

    public class labExercise1

    {

    public static void main (String[] args)

    {

    int sum = 0;

    double interestRate = 5.0;

    double monthlyPayment=0;

    double totalPayment=0;

    String input = JOptionPane. showInputDialog (null,"Enter the loan amount: ($) ","Lab Exercise 1", 2);

    double loanAmount = Double. parseDouble (input);

    String input1 = JOptionPane. showInputDialog (null,"Enter the loan period (years) : ","Lab Exercise 1",2);

    double numberOfYears = Double. parseDouble (input1);

    JOptionPane. showConfirmDialog (null,"The loan amount is $" + loanAmount + ", and the loan duration is " + numberOfYears + "year (s). Continue?","Lab Exercise 1",2);

    String s1 = null;

    System. out. print ("Interest Rate (%) Monthly Payment ($) Total Payment ($) ");

    s1 = "Interest Rate (%) Monthly Payment ($) Total Payment ($) ";

    while (interestRate < = 8.0)

    {

    double monthlyInterestRate = interestRate / 1200;

    monthlyPayment = loanAmount * monthlyInterestRate / (1 - 1 / Math. pow (1 + monthlyInterestRate, numberOfYears * 12));

    totalPayment = monthlyPayment * numberOfYears * 12;

    s1 = s1 + String. format ("%.3f%30.2f %40.2f ", interestRate, monthlyPayment, totalPayment) + " ";

    System. out. println (s1);

    interestRate = interestRate + 1.0 / 8;

    }

    //s1 = String. format ("%16.3f%19.2f%19.2f ", interestRate, monthlyPayment, totalPayment);

    System. out. println (s1);

    JOptionPane. showMessageDialog (null, s1,"Lab Exercise 1",3);

    }

    }

    Explanation:

    Take the loan amount and period as inputs from the user. Calculate the monthly interest rate by dividing the interest rate with 1200. Calculate total payment using the following the formula: totalPayment = monthlyPayment * numberOfYears * 12;
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a well-commented Java program that answers the following questions in complete sentences such that the reader does not have to know ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers