98 lines
6.6 KiB
HTML
98 lines
6.6 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
|
<html>
|
|
<head>
|
|
<title>Investment.java</title>
|
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
|
<style type="text/css">
|
|
<!--
|
|
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
|
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
|
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
|
.literal {color: #cc7832}
|
|
.ST3 {font-family: monospace; font-weight: bold; font-style: italic}
|
|
.ST0 {color: #287bde}
|
|
.string {color: #6a8759}
|
|
.number {color: #6897bb}
|
|
.ST1 {color: #ffc66d}
|
|
.comment {color: #808080}
|
|
.whitespace {color: #505050}
|
|
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
|
.ST4 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
|
-->
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/MP1_FX_CalebFontenot/src/mp1_fx_calebfontenot/Investment.java</td></tr></table>
|
|
<pre>
|
|
<span class="comment">/*</span>
|
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
|
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
|
|
<span class="comment"> */</span>
|
|
<span class="literal">package</span> mp1_fx_calebfontenot;
|
|
|
|
<span class="literal">import</span> java.text.NumberFormat;
|
|
<span class="literal">import</span> java.util.Locale;
|
|
<span class="literal">import</span> javafx.application.Application;
|
|
<span class="literal">import</span> javafx.geometry.Pos;
|
|
<span class="literal">import</span> javafx.scene.Scene;
|
|
<span class="literal">import</span> javafx.scene.control.Button;
|
|
<span class="literal">import</span> javafx.scene.control.Label;
|
|
<span class="literal">import</span> javafx.scene.control.TextField;
|
|
<span class="literal">import</span> javafx.scene.layout.GridPane;
|
|
<span class="literal">import</span> javafx.stage.Stage;
|
|
|
|
<span class="comment">/**</span>
|
|
<span class="comment"> *</span>
|
|
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
|
|
<span class="comment">*/</span>
|
|
<span class="literal">public</span> <span class="literal">class</span> Investment <span class="literal">extends</span> Application {
|
|
|
|
@Override
|
|
<span class="literal">public</span> <span class="literal">void</span> <span class="ST1">start</span>(Stage primaryStage) <span class="literal">throws</span> Exception {
|
|
GridPane gPane = <span class="literal">new</span> GridPane();
|
|
gPane.setAlignment(Pos.<span class="ST2">CENTER</span>);
|
|
gPane.add(<span class="literal">new</span> Label(<span class="string">"</span><span class="string">Investment Amount</span><span class="string">"</span>), <span class="number">0</span>, <span class="number">0</span>);
|
|
TextField investmentAmount = <span class="literal">new</span> TextField();
|
|
gPane.add(investmentAmount, <span class="number">1</span>, <span class="number">0</span>);
|
|
|
|
gPane.add(<span class="literal">new</span> Label(<span class="string">"</span><span class="string">Number of Years: </span><span class="string">"</span>), <span class="number">0</span>, <span class="number">1</span>);
|
|
TextField numOfYears = <span class="literal">new</span> TextField();
|
|
gPane.add(numOfYears, <span class="number">1</span>, <span class="number">1</span>);
|
|
|
|
gPane.add(<span class="literal">new</span> Label(<span class="string">"</span><span class="string">Annual Interest Rate:</span><span class="string">"</span>), <span class="number">0</span>, <span class="number">2</span>);
|
|
TextField annualInterestRate = <span class="literal">new</span> TextField();
|
|
gPane.add(annualInterestRate, <span class="number">1</span>, <span class="number">2</span>);
|
|
|
|
gPane.add(<span class="literal">new</span> Label(<span class="string">"</span><span class="string">Future value:</span><span class="string">"</span>), <span class="number">0</span>, <span class="number">3</span>);
|
|
TextField futureValue = <span class="literal">new</span> TextField();
|
|
gPane.add(futureValue, <span class="number">1</span>, <span class="number">3</span>);
|
|
|
|
Button calculateButton = <span class="literal">new</span> Button(<span class="string">"</span><span class="string">Calculate</span><span class="string">"</span>);
|
|
gPane.add(calculateButton, <span class="number">1</span>, <span class="number">4</span>);
|
|
calculateButton.alignmentProperty().set(Pos.<span class="ST2">CENTER_RIGHT</span>);
|
|
|
|
calculateButton.setOnAction(e -> {
|
|
<span class="literal">double</span> investment = Double.<span class="ST3">parseDouble</span>(investmentAmount.getText());
|
|
<span class="literal">double</span> rate = Double.<span class="ST3">parseDouble</span>(annualInterestRate.getText()) / <span class="number">100.0</span>;
|
|
<span class="literal">double</span> years = Double.<span class="ST3">parseDouble</span>(numOfYears.getText());
|
|
<span class="literal">double</span> output = investment * Math.<span class="ST3">pow</span>(<span class="number">1</span> + rate / <span class="number">12</span>, <span class="number">12</span> * years);
|
|
<span class="comment">// Round off</span>
|
|
<span class="comment">// double scale = Math.pow(10, 2);</span>
|
|
<span class="comment">//output = Math.round(output * scale) / scale;</span>
|
|
NumberFormat nf = NumberFormat.<span class="ST3">getCurrencyInstance</span>(Locale.<span class="ST2">US</span>);
|
|
futureValue.setText(nf.format(output));
|
|
System.<span class="ST2">out</span>.println(output + <span class="string">"</span><span class="string">, </span><span class="string">"</span> + nf.format(output));
|
|
});
|
|
Scene scene = <span class="literal">new</span> Scene(gPane);
|
|
primaryStage.setTitle(<span class="string">"</span><span class="string">ROI Calculator</span><span class="string">"</span>);
|
|
primaryStage.setScene(scene);
|
|
primaryStage.show();
|
|
}
|
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST4">main</span>(String[] args) {
|
|
<span class="ST3">launch</span>(args);
|
|
}
|
|
}
|
|
|
|
</pre></body>
|
|
</html>
|