Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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);
}
}
}

The solution to Programming Exercise 5.21 is given, but you will need to adapt it to a GUI version (alterna tively, you may write it on your own). There are two modifications to the instructions given in the text: 1. Display data for interest rates between 3% and 6% in increments of.5%. (WhichIdid already) 2. Include a graphic at the top that represents the company logo (any logo will doO Note that your image goes in a folder located within yourNetBeans project: /build classes image

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 );
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote