/home/caleb/ASDV-Java/Semester 3/Assignments/MP1_FX_CalebFontenot/src/mp1_fx_calebfontenot/Investment.java |
nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt
nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java
package mp1_fx_calebfontenot;
import java.text.NumberFormat;
import java.util.Locale;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
public class Investment extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
GridPane gPane = new GridPane();
gPane.setAlignment(Pos.CENTER);
gPane.add(new Label("Investment Amount"), 0, 0);
TextField investmentAmount = new TextField();
gPane.add(investmentAmount, 1, 0);
gPane.add(new Label("Number of Years: "), 0, 1);
TextField numOfYears = new TextField();
gPane.add(numOfYears, 1, 1);
gPane.add(new Label("Annual Interest Rate:"), 0, 2);
TextField annualInterestRate = new TextField();
gPane.add(annualInterestRate, 1, 2);
gPane.add(new Label("Future value:"), 0, 3);
TextField futureValue = new TextField();
gPane.add(futureValue, 1, 3);
Button calculateButton = new Button("Calculate");
gPane.add(calculateButton, 1, 4);
calculateButton.alignmentProperty().set(Pos.CENTER_RIGHT);
calculateButton.setOnAction(e -> {
double investment = Double.parseDouble(investmentAmount.getText());
double rate = Double.parseDouble(annualInterestRate.getText()) / 100.0;
double years = Double.parseDouble(numOfYears.getText());
double output = investment * Math.pow(1 + rate / 12, 12 * years);
NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
futureValue.setText(nf.format(output));
System.out.println(output + ", " + nf.format(output));
});
Scene scene = new Scene(gPane);
primaryStage.setTitle("ROI Calculator");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}