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

JAVA OR JAVA FX, NO PICTURE CODE PLS Loan.java // Implements Seriablizable to su

ID: 3741695 • Letter: J

Question

JAVA OR JAVA FX, NO PICTURE CODE PLS

Loan.java

// Implements Seriablizable to support object IO  
public class Loan implements java.io.Serializable {
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 -
(Math.pow(1 / (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;
}
}

6.13 (Compare loans with various interest rates) Rewrite Programming Exercise I to create a GUI, as shown in Figure 16.41b. Your program should let the user enter the loan ar 5. 21 s, and it should display the monthly and total payments for each interest starting from 5% to 8%, with increments of one-eighth, in a text area. field rate

Explanation / Answer

ANS:-

PROGRAM :-

ANS:-

PROGRAM :-

importjavafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; import javafx.stage.Stage; /** * (Compare loans with various interest rates) * Rewrite Programming Exercise 5.21 to create a GUI, * as shown in Figure 16.41b. Your program should let * the user enter the loan amount and loan period in * the number of years from text fields, and it should * display the monthly and total payments for each interest * rate starting from 5 percent to 8 percent, * with increments of one-eighth, in a text area. * * Created by luizsa on 9/26/14. */ public class Exercise_13 extends Application { TextField tfLoanAmount = new TextField(); TextField tfNumOfYears = new TextField(); TextArea textArea = new TextArea(); @Override public void start(Stage primaryStage) { EventHandler<ActionEvent> handler = event -> updateRates(); tfNumOfYears.setOnAction(handler); tfLoanAmount.setOnAction(handler); HBox topPane = new HBox(); topPane.setSpacing(10); topPane.setPadding(new Insets(5)); Label lblLoanAmount = new Label("Loan Amount:", tfLoanAmount); lblLoanAmount.setContentDisplay(ContentDisplay.RIGHT); Label lblNumOfYears = new Label("Number Of Years:", tfNumOfYears); lblNumOfYears.setContentDisplay(ContentDisplay.RIGHT); Button btShowTable = new Button("Show Table"); btShowTable.setOnAction(handler); topPane.getChildren().addAll(lblLoanAmount, lblNumOfYears, btShowTable); BorderPane borderPane = new BorderPane(textArea); borderPane.setTop(topPane); primaryStage.setScene(new Scene(borderPane)); primaryStage.setTitle("Display Loan"); primaryStage.show(); } private void updateRates() { double annualInterestRate = 5.00; double loanAmount = Double.parseDouble(tfLoanAmount.getText()); double numberOfYears = Double.parseDouble(tfNumOfYears.getText()); String s = String.format("%-1s%20s%20s ", "Interest Rate", "Monthly Payment", "Total Payment"); // making loop to display different interest rates for ( ; annualInterestRate <= 8.00; annualInterestRate += 0.125) { // calculating monthly and total payment rates double monthlyInterestRate = annualInterestRate / 1200; double monthlyPayment = loanAmount * monthlyInterestRate / (1 - 1 / Math.pow(1 + monthlyInterestRate, numberOfYears * 12)); double totalPayment = monthlyPayment * numberOfYears * 12; // making % string for formatting reasons... String str = "%"; // Displaying formatted info s += String.format("%-1.3f%s%19.2f%30.2f ", annualInterestRate, str, ((int) (monthlyPayment * 100) / 100.0), ((int) (totalPayment * 100) / 100.0)); } textArea.setText(s); } public static void main(String[] args) { Application.launch(args); } }