Question

A bank offers college loans that can be repaid in 5, 10, 15, 20, 25, or...

A bank offers college loans that can be repaid in 5, 10, 15, 20, 25, or 30 years. Write an app that allows the user to enter the amount of the loan and the annual interest rate. Based on these values, the app should display the loan lengths in years and their corresponding monthly payments.  

Design the form window using javaFX as follows:

  • Enter the Amount Of Loan and Interest Rate using TextField objects (remember that it will be necessary to convert the text String from the TextFields using a parse, method, e.g. Double.parseDouble()
  • Enter the Number Of Years using six RadioButton objects
  • Calculate the Monthly Payment displayed in a Label when a Button executes an event handler (since the app will only calculate the monthly payment for the currently selected RadioButton, it will not be necessary to also display the loan length in years as part of the output specified in the text)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear Student,

I have created sample javafx application for the scenario you have asked in the question:-

1. I have used three files to create this project and the comments are used in the file for your ready reference.

2. These files are (a) MonthlyPaymentCalculatorMain.java

(b) FXMLMonthlyPaymentCalculatorController

(c) FXMLMonthlyPaymentCalculator.fxml

3. Screenshot of MonthlyPaymentCalculatorMain.java which is mentioned below:-

4. Screenshot of FXMLMonthlyPaymentCalculatorController.java file is mentioned below:-

5. Screenshot of FXMLMonthlyPaymentCalculator.fxml file is mentioned below:-

6. MonthlyPaymentCalculatorMain.java file in textual format is mentioned below:-

package javafx.monthly.payment;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;

public class MonthlyPaymentCalculatorMain extends Application{

@FXML
private StackPane stackPane;

//Overriding start method of javafx Application class
public void start(Stage stage) throws Exception{

try{
   //Creating root class object with the given xml file placed in resource folder
Parent root = FXMLLoader.load(getClass().getResource("/FXMLMonthlyPaymentCalculator.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
  
//Setting title
stage.setTitle("Java FX Demo Calculator");
  
//Showing stage
stage.show();
  
stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
public void handle(WindowEvent arg0) {
Platform.exit();
}
});
}
catch (Exception e){
throw e;
}
}

//Main method
public static void main(String[] args){
try{
launch(args);
}
catch (Exception e){
e.printStackTrace();
}
}
}

7. FXMLMonthlyPaymentCacluatorController.java file in textual format is mentioned below:-

package javafx.monthly.payment;

import javafx.fxml.FXML;

import javafx.scene.control.TextField;

import javafx.scene.control.ToggleGroup;

import javafx.event.ActionEvent;

import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;

public class FXMLMonthlyPaymentCalculatorController {
  
   //Declaring TextBox for loan amount
   @FXML
   private TextField txtLoanAmount;
  
   //Declaring TextBox for interest rate
   @FXML
   private TextField txtInterestRate;
  
   //Declaring togglegroup for loan tenure
   @FXML
   private ToggleGroup loanLengthOfYears;
  
   //Declaring label for showing final output
   @FXML
   private Label lblCalculatedMonthlyPayment;

   /*This method will be invoked only on clicking radio button and it will set the
   label with the calculated monthly payment*/
   @FXML
   public void calculateMonthlyPayment(ActionEvent event) {
      
       //Reading loan amount
       String strLoanAmount=txtLoanAmount.getText();
      
       //Reading loan interest rate
       String strInterestRate=txtInterestRate.getText();
      
       /*Perform action for calculating monthly payment only if loan amount and
       interest rate are not blank or not entered by user*/
       if(!strLoanAmount.isBlank() && !strInterestRate.isBlank()) {
          
           //convert loan amount to double using parse method
           double loanAmount=Double.parseDouble(strLoanAmount);
          
           /*convert interest rate to double using parse method and divide it
           by 12*100 to get interest per month*/
           double interestRate=Double.parseDouble(strInterestRate)/(12*100);
          
           //Get selected radio button of loan length
           RadioButton selectedLoanLengthInYears=(RadioButton) loanLengthOfYears.getSelectedToggle();
          
           //Read loan length
           String strLoanLength=selectedLoanLengthInYears.getText();
          
           ////Parse loan length to int and multiply it to 12 to get the no of months
           int loanLength=Integer.parseInt(strLoanLength)*12;
          
           //Calculate monthly payment using the below formula
           double monthlyPayment=(loanAmount*interestRate*Math.pow(1+interestRate,loanLength))/
                   (Math.pow(1+interestRate,loanLength)-1);
          
           //round off monthly payment to nearest integer
           long monthlyPaymentRoundOff=Math.round(monthlyPayment);
          
           //Display the monthly payment in label
           lblCalculatedMonthlyPayment.setText("Monthly payment is "+monthlyPaymentRoundOff);
          
       }
   }
}

8. FXMLMonthlyPaymentCalculator.fxml file in textual format is mentioned below:-

<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.ToggleGroup?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity"
minWidth="-Infinity" prefHeight="561.0" prefWidth="778.0" xmlns="http://javafx.com/javafx/11.0.1"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="javafx.monthly.payment.FXMLMonthlyPaymentCalculatorController">
<children>
<Label layoutX="212.0" layoutY="35.0" prefHeight="35.0" prefWidth="402.0" text="Loan Monthly Payment Calculator">
<font>
<Font name="System Bold" size="24.0" />
</font>
</Label>
<TextField fx:id="txtLoanAmount" layoutX="339.0" layoutY="103.0"/>
<TextField fx:id="txtInterestRate" layoutX="339.0" layoutY="148.0"/>
<Label layoutX="121.0" layoutY="105.0" prefHeight="20.0" prefWidth="168.0" text="Enter the Amount of loan">
<font>
<Font size="14.0" />
</font>
</Label>
<Label layoutX="121.0" layoutY="152.0" prefHeight="17.0" prefWidth="137.0" text="Interest Rate">
<font>
<Font size="14.0" />
</font>
</Label>
<RadioButton layoutX="339.0" layoutY="201.0" mnemonicParsing="false" onAction="#calculateMonthlyPayment" text="5">
<toggleGroup>
<ToggleGroup fx:id="loanLengthOfYears" />
</toggleGroup>
</RadioButton>
<RadioButton layoutX="375.0" layoutY="201.0" mnemonicParsing="false" onAction="#calculateMonthlyPayment" text="10"
toggleGroup="$loanLengthOfYears" />
<RadioButton layoutX="424.0" layoutY="201.0" mnemonicParsing="false" onAction="#calculateMonthlyPayment" text="15"
toggleGroup="$loanLengthOfYears" />
<RadioButton layoutX="471.0" layoutY="201.0" mnemonicParsing="false" onAction="#calculateMonthlyPayment" text="20"
toggleGroup="$loanLengthOfYears" />
<RadioButton layoutX="522.0" layoutY="202.0" mnemonicParsing="false" onAction="#calculateMonthlyPayment" text="25"
toggleGroup="$loanLengthOfYears" />
<RadioButton layoutX="566.0" layoutY="202.0" mnemonicParsing="false" onAction="#calculateMonthlyPayment" text="30"
toggleGroup="$loanLengthOfYears" />
<Label layoutX="121.0" layoutY="200.0" prefHeight="17.0" prefWidth="137.0" text="Enter no of years">
<font>
<Font size="14.0" />
</font>
</Label>
<Label fx:id="lblCalculatedMonthlyPayment" layoutX="221.0" layoutY="263.0" prefHeight="35.0" prefWidth="429.0" />
</children>
</AnchorPane>

9. Output of the above code is mentioned below:-

10. As most of the code is commented. Still you may require need to clear doubt to any of your queries inside the code. Then you may feel free to reach me through comments section, I will reply you as early as possible.

11. Inside controller I have used generalized formula to calculate the monthly payment, if you have different formula for calculating monthly payment you can just replace the logic inside the calculateMonthlyPayment method of controller class.

Thanks!!

Happy Learning!!

Add a comment
Know the answer?
Add Answer to:
A bank offers college loans that can be repaid in 5, 10, 15, 20, 25, or...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Need pseudocode flowchart only! Please complete is question as a pseudocode and flowchart for Java. 12.5...

    Need pseudocode flowchart only! Please complete is question as a pseudocode and flowchart for Java. 12.5 (College Loan Payoff Calculator App) A bank offers college loans that can be repaid in 5,10, 15, 20, 25, or 30 years. Write an app that allows the user to enter the amount of the loan and the annual interest rate. Based on these values, the app should display the loan lengths in years and their corresponding monthly payments.

  • plz help LESSON 84 The Monthly Payment Most mortgage loans are repaid in equal payments. Each...

    plz help LESSON 84 The Monthly Payment Most mortgage loans are repaid in equal payments. Each payment includes an amount for payment of interest and an amount for payment of the principal of the loan. The amount of interest is calculated using the simple interest formula. Each payment you make decreases the amount of the principal you owe. PRINCIPAL PAYMENT - MONTHLY PAYMENT - INTEREST PAYMENT NEW PRINCIPAL - PREVIOUS PRINCIPAL PRINCIPAL PAYMENT Complete the table below. Mortgage Amount Interest...

  • ***Please use java code for the question below*** Write a program that calculates the future value...

    ***Please use java code for the question below*** Write a program that calculates the future value of a given investment at a given interest rate for a specified number of years. The formula for this calculation is: value = investmentAmount * (1 + monthly interest rate)years*12 Use text fields for the user to enter the numbers (Investment Amount, Number of Years, and Annual Interest). To get/load data from the textbox, (in this case doubles) use the following structure: (bold are...

  • Tip Calculator App & Order Using NetBeans create a new JavaFX project with two classes TipCalculator...

    Tip Calculator App & Order Using NetBeans create a new JavaFX project with two classes TipCalculator (the JavaFX class) and Order Create the Tip Calculator as follows: Start with an Order class with two instance variables, item a String and price a double; include two constructors, a no-parameter constructor that passes default values empty String and zero (0) to the second constructor which then calls the set methods for item and price; the set method for price validates that price...

  • MATLAB!!! CAN SOMEONE SOLVE THIS PROBLEM ON MATLAB?? THANK YOU PART B: HOUSING LOAN CALCULATOR In this part of the assignment, you are expected to develop a program that calculates housing loan pay-...

    MATLAB!!! CAN SOMEONE SOLVE THIS PROBLEM ON MATLAB?? THANK YOU PART B: HOUSING LOAN CALCULATOR In this part of the assignment, you are expected to develop a program that calculates housing loan pay- ments based on compound interest formulas The program should prompt a user to input the amount borrowed (principal), p, the number of monthly payments, n, and an annual interest rate in R percent. The program should convert the annual interest rate R into a monthly interest rate...

  • Succeeding in Business with Microsoft Excel 2013. Chapter 6, Steps to Success Level 1 • Annual...

    Succeeding in Business with Microsoft Excel 2013. Chapter 6, Steps to Success Level 1 • Annual Interest Tumi • Loan Duration in Years • Payment per Period • Present Value • Future Value worksheet, merged and include the title TZEdge Advertising Options on your workshe the appropriate data an listed. For all options ised as the compounding pe ounding period costing $65,000. This equal quarterly install calculate the annual interest rate r $55,000 and indi- nis amount, with fixed is...

  • CIS 221 Loan Calculator Enhancement Introduction You are a systems analyst working for a company that...

    CIS 221 Loan Calculator Enhancement Introduction You are a systems analyst working for a company that provides loans to customers. Your manager has asked you to enhance and correct their existing Loan Calculator program, which is designed to calculate monthly and total payments given the loan amount, the annual interest rate, and the duration of the loan. Although the current version of the program (hereby termed the “As Is” version) has some functionality, there are several missing pieces, and the...

  • Oject Description: u own five apartment complexes. You created a dataset listing the apartment nu...

    please post with pictures of step by step solution oject Description: u own five apartment complexes. You created a dataset listing the apartment numbers, apartment complex mes, as last remodeled. You want artments need to number of bedrooms, rental price, whether the apartment is occupied or not, and the date the apartment to insert some functions to perform calculations to help you decide which be remodeled. To focus on the apartments that need to be remodeled, you will use vanced...

  • a.   Find the FV of $1,000 invested to earn 10% annually 5 years from now. Answer...

    a.   Find the FV of $1,000 invested to earn 10% annually 5 years from now. Answer this question by using a math formula and also by using the Excel function wizard. Inputs: PV = 1000 I/YR = 10% N = 5 Formula: FV = PV(1+I)^N = Wizard (FV): $1,610.51 Note: When you use the wizard and fill in the menu items, the result is the formula you see on the formula line if you click on cell E12. Put the...

  • In this project, you will work with sales data from Top’t Corn, a popcorn company with...

    In this project, you will work with sales data from Top’t Corn, a popcorn company with an online store, multiple food trucks, and two retail stores. You will begin by inserting a new worksheet and entering sales data for the four food truck locations, formatting the data, and calculating totals. You will create a pie chart to represent the total units sold by location and a column chart to represent sales by popcorn type. You will format the charts, and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT