Create a GUI program using BORDER Pane that shows a table of

Create a GUI program using BORDER Pane that shows a table of loan comparison information.

Specifications

You will need to ask for a Loan Amount, and Number of Years. The user will input these via text fields.

There will be a Show Table button that when pressed will create a table with monthly and total payments for each interest rate starting from 5% to 8%, in increments of 0.125%. This will be displayed in a Grid Pane.

The GUI should look something like this:

The interest rate should always have 3 places after the decimal point. Monthly Payment and Total Payment should be formatted as Currency.

Hint: Look at the NumberFormat class or the format method in the String class.

Use a Border Pane for holding everything. Use the NORTH area for user interaction. Use the CENTER area for the table.

The code for the Loan Class is included at the end of this document.

Error Checking

Inputs

Make sure all fields are numbers.

The Loan Amount can be between $1,000 and $100,000.

The Number of Years can be between 1 and 20.

All fields need to be correct when the Show Table button is pressed.

The user will be able to change any of the fields and press the Show Table button.

Use a Try-Catch blocks where you deem appropriate.

******Code for loan class*****

public class Loan {

private double annualInterestRate;

private int numberOfYears;

private double loanAmount;

private java.util.Date loanDate;

/** Default constructor */

public Loan() {

    this(2.5, 1, 1000);

}

/** Construct a loan with specified annual interest rate,

      number of years, and loan amount

    */

public Loan(double annualInterestRate, int numberOfYears,

      double loanAmount) {

    this.annualInterestRate = annualInterestRate;

    this.numberOfYears = numberOfYears;

    this.loanAmount = loanAmount;

    loanDate = new java.util.Date();

}

/** Return annualInterestRate */

public double getAnnualInterestRate() {

    return annualInterestRate;

}

/** Set a new annualInterestRate */

public void setAnnualInterestRate(double annualInterestRate) {

  this.annualInterestRate = annualInterestRate;

}

/** Return numberOfYears */

public int getNumberOfYears() {

    return numberOfYears;

}

/** Set a new numberOfYears */

public void setNumberOfYears(int numberOfYears) {

    this.numberOfYears = numberOfYears;

}

/** Return loanAmount */

public double getLoanAmount() {

    return loanAmount;

}

/** Set a newloanAmount */

public void setLoanAmount(double loanAmount) {

    this.loanAmount = loanAmount;

}

/** Find monthly payment */

public double getMonthlyPayment() {

    double monthlyInterestRate = annualInterestRate / 1200;

    double monthlyPayment = loanAmount * monthlyInterestRate / (1 -

      (1 / Math.pow(1 + monthlyInterestRate, numberOfYears * 12)));

    return monthlyPayment;   

}

/** Find total payment */

public double getTotalPayment() {

    double totalPayment = getMonthlyPayment() * numberOfYears * 12;

    return totalPayment;   

}

/** Return loan date */

public java.util.Date getLoanDate() {

    return loanDate;

}

}

Loan Comparison Loan Amount 10000 Number of Years 5 Interest Rate Monthly Payment Total Payment $188.71 5.000 $11,322.74 $11,357.13 5.125 $189.28 $189.85 $11,391.59 5.250 $190.43 $11,426.11 5.375 $191.01 $11,460.69 5.500 $11,495.34 $191.58 5.625 $192.16 $11,530.06 5.750 $11,564.83 $192.74 5.875 6.000 $193.32 $11,599.68 Show Table

Solution

public class program extends Application

{

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.TextArea;
import javafx.scene.control.Button;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.BorderPane;
import javafx.geometry.Pos;

public class program extends Application

{

protected TextField tfLoanAmount = new TextField();
protected TextField tfNumberOfYears = new TextField();
protected TextArea textArea = new TextArea();
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
tfNumberOfYears.setPrefColumnCount(2);
tfLoanAmount.setPrefColumnCount(7);
textArea.setPrefColumnCount(30);
// Create a button
Button btShowTable = new Button(\"Show Table\");
// Create a hbox
HBox paneForControls = new HBox(10);
paneForControls.setAlignment(Pos.CENTER);
paneForControls.getChildren().addAll(new Label(\"Loan Amount\"), tfLoanAmount,
new Label(\"Number of Years\"), tfNumberOfYears, btShowTable);
// Create a scrollPane
ScrollPane scrollPane = new ScrollPane(textArea);
// Create a pane
BorderPane pane = new BorderPane();
pane.setTop(paneForControls);
pane.setCenter(textArea);
// Create and register handler
btShowTable.setOnAction(e -> {
print();
});
// Create a scene and place it in the stage
Scene scene = new Scene(pane);
primaryStage.setTitle(\"program \"); // Set the stage title
primaryStage.setScene(scene); // Place the scene in the stage
primaryStage.show(); // Display the stage
}
private void print() {
// Create a output string
String output = \"\";
double monthlyInterestRate; // Monthly interest rate
double monthlyPayment; // Monthly payment
// Add table header
output += \"Interest Rate Monthly Payment Total Payment\ \";
// Calculate and add table with interest rates to output
for (double i = 5.0; i <= 8; i += 0.125) {
monthlyInterestRate = i / 1200;
monthlyPayment = Double.parseDouble(tfLoanAmount.getText()) *
monthlyInterestRate / (1 - 1 / Math.pow(1 + monthlyInterestRate,
Double.parseDouble(tfNumberOfYears.getText()) * 12));
output += String.format(\"%-24.3f%-34.2f%-8.2f\ \", i,
monthlyPayment, (monthlyPayment * 12) *
Double.parseDouble(tfNumberOfYears.getText()));
}
textArea.setText(output);
}
}
Create a GUI program using BORDER Pane that shows a table of loan comparison information. Specifications You will need to ask for a Loan Amount, and Number of Y
Create a GUI program using BORDER Pane that shows a table of loan comparison information. Specifications You will need to ask for a Loan Amount, and Number of Y
Create a GUI program using BORDER Pane that shows a table of loan comparison information. Specifications You will need to ask for a Loan Amount, and Number of Y
Create a GUI program using BORDER Pane that shows a table of loan comparison information. Specifications You will need to ask for a Loan Amount, and Number of Y

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site