PLEASE DO NOT RESPOND IN PICTURE. TEXT ONLY. Code which needs to be converted to
ID: 3849269 • Letter: P
Question
PLEASE DO NOT RESPOND IN PICTURE. TEXT ONLY.
Code which needs to be converted to GUI:
public class Exercise05_21 {
// Main method
public static void main(String[] args) {
java.util.Scanner input = new java.util.Scanner(System.in);
// Enter loan amount
System.out.print("Enter loan amount, for example 120000.95: ");
double loanAmount = input.nextDouble();
// Enter number of years
System.out.print("Enter number of years as an integer, for example 5: ");
// Convert string to int
int numOfYears = input.nextInt();
// Display the header
System.out.printf("%-20s%-20s%-20s ", "Interest Rate", "Monthly Payment", "Total Payment");
for (double annualInterestRate = 3.0; annualInterestRate <= 6.0;
annualInterestRate += .5) {
// Obtain monthly interest rate
double monthlyInterestRate = annualInterestRate / 1200;
// Compute mortgage
double monthlyPayment = loanAmount * monthlyInterestRate /
(1 - (Math.pow(1 / (1 + monthlyInterestRate), numOfYears * 12)));
double totalPayment = monthlyPayment * numOfYears * 12;
// Display results
System.out.printf("%5.3f%c %20.2f %20.2f ", annualInterestRate,
'%', monthlyPayment, totalPayment);
}
}
}
Explanation / Answer
Code:
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import java.awt.*;
import java.awt.event.*
public class TestCalc
{
static JFrame window;
static JPanel p;
static JLabel label1, label2;
static JTextField JTextField1, JTextField2;
static JButton b;
static JTextArea textArea;
static JScrollPane scrollPane;
static ButtonHandler handler;
public class MonPay
{
public static void main(String args[ ] )
{
System.out.println("Loan Monthly Payment Program ");
String strAmount, strIRate, strYears;
double amount, iRate, years, monPay, totalPay;
strAmount =
JOptionPane.showInputDialog(" Enter the amount of the Loan $: ");
strIRate =
JOptionPane.showInputDialog("Enter the % interest rate: ");
strYears =
JOptionPane.showInputDialog("Enter the # of years: ");
import javax.swing.JOptionPane; // include the JOptionPane library in swing
public class MonPay
{
public static void main(String args[ ] )
{
System.out.println("Loan Monthly Payment Program ");
String strAmount, strIRate, strYears;
double amount, iRate, years, monPay, totalPay;
strAmount =
JOptionPane.showInputDialog(" Enter the amount of the Loan $: ");
strIRate =
JOptionPane.showInputDialog("Enter the % interest rate: ");
strYears =
JOptionPane.showInputDialog("Enter the # of years: ");
amount = Double.parseDouble(strAmount);
iRate = Double.parseDouble(strIRate);
years = Double.parseDouble(strYears);
System.out.println("Enter the amount of the Loan $: " + amount + " ");
System.out.println("Enter the % interest rate: " + iRate +" ");
System.out.println("Enter the # of years: " + years +" ");
totalPay = (int)(totalPay * 100 + 0.5 ) / 100.0;
System.out.println("The monthly payment is : $" + monPay +" ");
System.out.println("The total amount paid is : $" + totalPay +" " );
System.exit( 0 );
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.