Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In Murach Java 6 th Edition FutureValueApplication.java import java.text.NumberFormat; import javafx.application.Application; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Alert; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField;
In Murach Java th Edition
FutureValueApplication.java
import java.text.NumberFormat;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class FutureValueApplication extends Application
private TextField investmentField;
private TextField interestRateField;
private TextField yearsField;
private TextField futureValueField;
public static void mainString args
launchargs;
@Override
public void startStage primaryStage
primaryStage.setTitleFuture Value Calculator";
GridPane grid new GridPane;
grid.setAlignmentPosTOPCENTER;
grid.setPaddingnew Insets;
grid.setHgap;
grid.setVgap;
Scene scene new Scenegrid;
grid.addnew LabelMonthly Investment:";
investmentField new TextField;
grid.addinvestmentField;
grid.addnew LabelYearly Interest Rate:";
interestRateField new TextField;
grid.addinterestRateField;
grid.addnew LabelYears:;
yearsField new TextField;
grid.addyearsField;
grid.addnew LabelFuture Value:";
futureValueField new TextField;
futureValueField.setEditablefalse;
grid.addfutureValueField;
Button calculateButton new ButtonCalculate;
calculateButton.setOnActionevent calculateButtonClicked;
Button exitButton new ButtonExit;
exitButton.setOnActionevent exitButtonClicked;
HBox buttonBox new HBox;
buttonBox.getChildrenaddcalculateButton;
buttonBox.getChildrenaddexitButton;
buttonBox.setAlignmentPosBOTTOMRIGHT;
grid.addbuttonBox;
primaryStage.setScenescene;
primaryStage.show;
private void calculateButtonClicked
Validation v new Validation;
String errorMsg ;
errorMsg visDoubleinvestmentFieldgetText
"Monthly Investment";
errorMsg visDoubleinterestRateFieldgetText
"Yearly Interest Rate";
errorMsg visIntegeryearsFieldgetText
"Years";
if errorMsgisEmpty
double investment Double.parseDouble
investmentField.getText;
double rate Double.parseDouble
interestRateField.getText;
int years Integer.parseInt
yearsField.getText;
double futureValue calculateFutureValue
investment, rate, years;
NumberFormat currency NumberFormat.getCurrencyInstance;
futureValueField.setTextcurrencyformatfutureValue;
else
Alert alert new AlertAlertAlertType.ERROR;
alert.setHeaderTextInvalid Data";
alert.setContentTexterrorMsg;
alert.showAndWait;
public double calculateFutureValuedouble investment, double rate, int years
double futureValue ;
convert yearly values to monthly values
double monthlyInterestRate rate ;
int months years ;
for int i ; i months; i
futureValue futureValue investment
monthlyInterestRate;
return futureValue;
private void exitButtonClicked
System.exit; indicates a normal exit
Validation.java:
package com.murach.futurevalue;
public class Validation
private final String lineEnd;
public Validation
this.lineEnd
;
public ValidationString lineEnd
this.lineEnd lineEnd;
public String isPresentString value, String name
String msg ;
if valueisEmpty
msg name is required." lineEnd;
return msg;
public String isDoubleString value, String name
String msg ;
try
Double.parseDoublevalue;
catch NumberFormatException e
msg name must be a valid number." lineEnd;
return msg;
public String isIntegerString value, String name
String msg ;
try
Integer.parseIntvalue;
catch NumberFormatException e
msg name must be an integer." lineEnd;
return msg;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started