JavaFX Loan Calculator Application Design and Implementation

Verified

Added on  2025/05/08

|10
|766
|70
AI Summary
Desklib provides solved assignments and past papers for students.
Document Page
DESIGN
The design of the UI is created using the Balsamiq Tool. Balsamiq tool is one of the most
popular tools to create interfaces and wireframes. The design listed below will help in
understanding the idea and further will ease in writing the code for the GUI (Graphical User
Interface).
Figure 1 Design
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
CODING
// Importing Application Class to initialize the Interface of the program.
import javafx.application.Application;
// Importing Pos to calculate the position
import javafx.geometry.Pos;
// Importing Scene for intializing it
import javafx.scene.Scene;
// Importing the Buttons which will be used for performing an action
import javafx.scene.control.Button;
// importing label to insert label into it
import javafx.scene.control.Label;
// Importing Scroll Pane which will be used for scrolling the window
import javafx.scene.control.ScrollPane;
// Importing the Text Area to select the area.
import javafx.scene.control.TextArea;
// Importing the TextField which will be used for taking input by the user in a particular field.
import javafx.scene.control.TextField;
Document Page
// Import BorderPane to include the borders in a program.
import javafx.scene.layout.BorderPane;
// Importing the HBox to create a horizontal box in Application.
import javafx.scene.layout.HBox;
// Importing Stage to select the stage in a program.
import javafx.stage.Stage;
// Defining Public Class payments which will be extended by Application used as GUI
public class payments extends Application {
// Creating a TextField for entering the amount of loan by the user.
TextField amount_of_loan = new TextField();
// creating a Textfield Years which use to enter the years in a program.
TextField years = new TextField();
// Space is defined as TextArea which will be used for displaying the result of operation performed in the
program.
TextArea space = new TextArea();
@Override
Document Page
// Using the start method to intialize the intialstage of The program.
public void start(Stage initialStage) {
// Setting the prefColumn count to 2.
years.setPrefColumnCount(2);
// Amount of loan us being set to prefColumnCount which is being defined to 7.
amount_of_loan.setPrefColumnCount(7);
// For Space PrefColumnCont to 30
space.setPrefColumnCount(30);
// Button is being displayed which is named as calculate in the program.
Button display_table = new Button("Calculate");
// Creating a new HBox named as controls.
HBox controls = new HBox();
// Setting the position of the HBox at the ccenter.
controls.setAlignment(Pos.CENTER);
// Setting the spacing of controls.
controls.setSpacing(9);
// Creating the Label using the controls.
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
controls.getChildren().addAll(new Label("Amount of Loan"), amount_of_loan, new Label("Years"), years,
display_table);
// Scroll pane objects is being created named as spane.
ScrollPane spane;
// Intializing the spane as space textarea
spane = new ScrollPane(space);
// BorderPane Object is being Created named as bpane.
BorderPane bpane = new BorderPane();
//Setting the controls at the top of the border pane
bpane.setTop(controls);
// At center of the border pane TextArea is being alligned.
bpane.setCenter(space);
// Action is being set to the display button
display_table.setOnAction(b -> {
print();
});
// Scene is being created.
Scene scene = new Scene(bpane);
Document Page
// Scene is being set using intialstage setscene function.
initialStage.setScene(scene);
// Title page is being set to Payments
initialStage.setTitle("PAYMENTS");
// Showing the IntialStage of the program.
initialStage.show();
}
// Defining the Print function in a program
private void print(){
// Result is being intialiazed
String result;
// Result intialized
result = "";
// Creaing variable for calculation of Monthly interest Rate per month and Monthly payment
double interestRatePerMonth;
double paymentPerMonth;
// Result is being set and defined to perform the proper functionality.
result+="Rate of Interest Payment Per Month Final Payment \n";
// Iteration of the loop which will calculate the rate of interest ranging from 5% - 8%.
Document Page
for (double a = 5.0; a <= 8; a += 0.125){
// Calculating interestRateperMonth
interestRatePerMonth=a/1200;
// paymentperMonth is being Calculated
paymentPerMonth=Double.parseDouble(amount_of_loan.getText())*interestRatePerMonth/(1-1/
Math.pow(1+interestRatePerMonth, Double.parseDouble(years.getText())*12));
// Result is being stroed in this variable
result+=String.format("%-34.3f%-30.2f%-8.3f\n",a, paymentPerMonth,
(paymentPerMonth*12)*Double.parseDouble(years.getText()));
}
// Displaying the result in the textarea named as space.
space.setText(result);
}
public static void main(String[] args) {
launch(args);
}
}
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
OUTPUT
Figure 2 First Output
Figure 3 Second Output
Document Page
SELF EVALUATION
UI is correct or not?
The graphical user interface is developed correctly. The interface is created as per the design
which is created using the Balsamiq tool.
Figure 4 Third Output
Is the calculation correct?
The calculation is done correctly. The payment per month and the final payment is calculated on
the basis of the rate of interest. The application is running successfully and it can be seen below.
Figure 5 Fourth Output
Document Page
The table is displayed correctly or not?
The table is displayed correctly. The alignment of the values and the headings are done via
coding. The table is fully operational even when scrolled down. The results are shown below.
Figure 6 Fifth Output (1)
Figure 7 Fifth Output (2)
chevron_up_icon
1 out of 10
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]