push changes
This commit is contained in:
parent
d709a920cf
commit
40238e93f4
1
.gitignore
vendored
1
.gitignore
vendored
@ -147,3 +147,4 @@
|
||||
/Semester 3/Assignments/MP1_FX_CalebFontenot/nbproject/private/
|
||||
/Semester 3/Assignments/MP1_FX_CalebFontenot/build/
|
||||
/Semester 3/Assignments/MP1_FX_CalebFontenot/dist/
|
||||
/Semester 3/Assignments/RecursionDemo/target/
|
||||
|
@ -0,0 +1,85 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>BarChart.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}
|
||||
.ST4 {font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST0 {color: #287bde}
|
||||
.number {color: #6897bb}
|
||||
.string {color: #6a8759}
|
||||
.ST1 {color: #ffc66d}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST3 {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/BarChart.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> javafx.application.Application;
|
||||
<span class="literal">import</span> javafx.scene.Scene;
|
||||
<span class="literal">import</span> javafx.scene.layout.Pane;
|
||||
<span class="literal">import</span> javafx.scene.paint.Color;
|
||||
<span class="literal">import</span> javafx.scene.shape.Rectangle;
|
||||
<span class="literal">import</span> javafx.scene.text.Text;
|
||||
<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> BarChart <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 {
|
||||
Pane pane = <span class="literal">new</span> Pane();
|
||||
|
||||
<span class="literal">double</span> height = <span class="number">300</span>;
|
||||
<span class="literal">double</span> panelHeight = <span class="number">150</span>;
|
||||
Rectangle r1 = <span class="literal">new</span> Rectangle(<span class="number">1</span><span class="number">0</span>, panelHeight - height * <span class="number">0.2</span>, <span class="number">1</span><span class="number">00</span>, height * <span class="number">0.2</span>);
|
||||
r1.setFill(Color.<span class="ST2">RED</span>);
|
||||
Text text1 = <span class="literal">new</span> Text(<span class="number">1</span><span class="number">0</span>, panelHeight - height * <span class="number">0.2</span> - <span class="number">10</span>, <span class="string">"</span><span class="string">Project -- 20%</span><span class="string">"</span>);
|
||||
|
||||
Rectangle r2 = <span class="literal">new</span> Rectangle(<span class="number">10</span> + <span class="number">110</span>, panelHeight - height * <span class="number">0.1</span>, <span class="number">1</span><span class="number">00</span>, height * <span class="number">0.1</span>);
|
||||
r2.setFill(Color.<span class="ST2">BLUE</span>);
|
||||
Text text2 = <span class="literal">new</span> Text(<span class="number">10</span> + <span class="number">110</span>, panelHeight - height * <span class="number">0.1</span> - <span class="number">10</span>, <span class="string">"</span><span class="string">Quiz -- 10%</span><span class="string">"</span>);
|
||||
|
||||
Rectangle r3 = <span class="literal">new</span> Rectangle(<span class="number">10</span> + <span class="number">220</span>, panelHeight - height * <span class="number">0.3</span>, <span class="number">1</span><span class="number">00</span>, height * <span class="number">0.3</span>);
|
||||
r3.setFill(Color.<span class="ST2">GREEN</span>);
|
||||
Text text3 = <span class="literal">new</span> Text(<span class="number">10</span> + <span class="number">220</span>, panelHeight - height * <span class="number">0.3</span> - <span class="number">10</span>, <span class="string">"</span><span class="string">Midterm -- 30%</span><span class="string">"</span>);
|
||||
|
||||
Rectangle r4 = <span class="literal">new</span> Rectangle(<span class="number">10</span> + <span class="number">330</span>, panelHeight - height * <span class="number">0.4</span>, <span class="number">1</span><span class="number">00</span>, height * <span class="number">0.4</span>);
|
||||
r4.setFill(Color.<span class="ST2">ORANGE</span>);
|
||||
Text text4 = <span class="literal">new</span> Text(<span class="number">10</span> + <span class="number">330</span>, panelHeight - height * <span class="number">0.4</span> - <span class="number">10</span>, <span class="string">"</span><span class="string">Final -- 40%</span><span class="string">"</span>);
|
||||
|
||||
pane.getChildren().addAll(r1, text1, r2, text2, r3, text3, r4, text4);
|
||||
|
||||
<span class="comment">// Create a scene and place it in the stage</span>
|
||||
Scene scene = <span class="literal">new</span> Scene(pane, <span class="number">5</span><span class="number">00</span>, panelHeight);
|
||||
primaryStage.setTitle(<span class="string">"</span><span class="string">Bar Chart</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="ST3">main</span>(String[] args) {
|
||||
<span class="ST4">launch</span>(args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
@ -0,0 +1,109 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>Calculator.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}
|
||||
.number {color: #6897bb}
|
||||
.string {color: #6a8759}
|
||||
.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/Calculator.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="comment">import</span> <span class="comment">static</span> <span class="comment">java</span><span class="comment">.</span><span class="comment">lang</span><span class="comment">.</span><span class="comment">Double</span><span class="comment">.</span><span class="comment">parseDouble</span><span class="comment">;</span>
|
||||
<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.BorderPane;
|
||||
<span class="literal">import</span> javafx.scene.layout.FlowPane;
|
||||
<span class="literal">import</span> javafx.scene.layout.HBox;
|
||||
<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> Calculator <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 {
|
||||
FlowPane pane = <span class="literal">new</span> FlowPane();
|
||||
pane.setHgap(<span class="number">2</span>);
|
||||
TextField tfNumber1 = <span class="literal">new</span> TextField();
|
||||
TextField tfNumber2 = <span class="literal">new</span> TextField();
|
||||
TextField tfResult = <span class="literal">new</span> TextField();
|
||||
tfNumber1.setPrefColumnCount(<span class="number">3</span>);
|
||||
tfNumber2.setPrefColumnCount(<span class="number">3</span>);
|
||||
tfResult.setPrefColumnCount(<span class="number">3</span>);
|
||||
|
||||
pane.getChildren().addAll(<span class="literal">new</span> Label(<span class="string">"</span><span class="string">Number 1: </span><span class="string">"</span>), tfNumber1, <span class="literal">new</span> Label(<span class="string">"</span><span class="string">Number 2</span><span class="string">"</span>), tfNumber2, <span class="literal">new</span> Label(<span class="string">"</span><span class="string">Result: </span><span class="string">"</span>), tfResult);
|
||||
|
||||
HBox hBox = <span class="literal">new</span> HBox(<span class="number">5</span>);
|
||||
Button btAdd = <span class="literal">new</span> Button(<span class="string">"</span><span class="string">Add</span><span class="string">"</span>);
|
||||
Button btSubtract = <span class="literal">new</span> Button(<span class="string">"</span><span class="string">Subtract</span><span class="string">"</span>);
|
||||
Button btMultiply = <span class="literal">new</span> Button(<span class="string">"</span><span class="string">Multiply</span><span class="string">"</span>);
|
||||
Button btDivide = <span class="literal">new</span> Button(<span class="string">"</span><span class="string">Divide</span><span class="string">"</span>);
|
||||
hBox.setAlignment(Pos.<span class="ST2">CENTER</span>);
|
||||
hBox.getChildren().addAll(btAdd, btSubtract, btMultiply, btDivide);
|
||||
|
||||
BorderPane borderPane = <span class="literal">new</span> BorderPane();
|
||||
borderPane.setCenter(pane);
|
||||
borderPane.setBottom(hBox);
|
||||
BorderPane.<span class="ST3">setAlignment</span>(hBox, Pos.<span class="ST2">TOP_CENTER</span>);
|
||||
|
||||
Scene scene = <span class="literal">new</span> Scene(borderPane, <span class="number">2</span><span class="number">50</span>, <span class="number">1</span><span class="number">50</span>);
|
||||
primaryStage.setTitle(<span class="string">"</span><span class="string">Calculator</span><span class="string">"</span>);
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.show();
|
||||
|
||||
btAdd.setOnAction(e -> {
|
||||
tfResult.setText(Double.<span class="ST3">parseDouble</span>(tfNumber1.getText())
|
||||
+ Double.<span class="ST3">parseDouble</span>(tfNumber2.getText()) + <span class="string">""</span>);
|
||||
});
|
||||
|
||||
btSubtract.setOnAction(e -> {
|
||||
tfResult.setText(Double.<span class="ST3">parseDouble</span>(tfNumber1.getText())
|
||||
- Double.<span class="ST3">parseDouble</span>(tfNumber2.getText()) + <span class="string">""</span>);
|
||||
});
|
||||
|
||||
btMultiply.setOnAction(e -> {
|
||||
tfResult.setText(Double.<span class="ST3">parseDouble</span>(tfNumber1.getText())
|
||||
* Double.<span class="ST3">parseDouble</span>(tfNumber2.getText()) + <span class="string">""</span>);
|
||||
});
|
||||
|
||||
btDivide.setOnAction(e -> {
|
||||
tfResult.setText(Double.<span class="ST3">parseDouble</span>(tfNumber1.getText())
|
||||
/ Double.<span class="ST3">parseDouble</span>(tfNumber2.getText()) + <span class="string">""</span>);
|
||||
});
|
||||
|
||||
}
|
||||
<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>
|
@ -0,0 +1,97 @@
|
||||
<!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>
|
@ -0,0 +1,132 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>PieChart.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}
|
||||
.ST2 {font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST0 {color: #287bde}
|
||||
.number {color: #6897bb}
|
||||
.string {color: #6a8759}
|
||||
.ST1 {color: #ffc66d}
|
||||
.ST4 {color: #8a653b}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
.ST3 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST5 {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/PieChart.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.util.ArrayList;
|
||||
<span class="literal">import</span> javafx.application.Application;
|
||||
<span class="comment">import</span> <span class="comment">javafx</span><span class="comment">.</span><span class="comment">geometry</span><span class="comment">.</span><span class="comment">Pos</span><span class="comment">;</span>
|
||||
<span class="literal">import</span> javafx.scene.Group;
|
||||
<span class="literal">import</span> javafx.scene.Scene;
|
||||
<span class="literal">import</span> javafx.scene.layout.Pane;
|
||||
<span class="comment">import</span> <span class="comment">javafx</span><span class="comment">.</span><span class="comment">scene</span><span class="comment">.</span><span class="comment">layout</span><span class="comment">.</span><span class="comment">StackPane</span><span class="comment">;</span>
|
||||
<span class="literal">import</span> javafx.scene.paint.Color;
|
||||
<span class="literal">import</span> javafx.scene.shape.Arc;
|
||||
<span class="literal">import</span> javafx.scene.shape.ArcType;
|
||||
<span class="literal">import</span> javafx.scene.text.Text;
|
||||
<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> PieChart <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 {
|
||||
<span class="comment">// Create pane</span>
|
||||
Pane pane = <span class="literal">new</span> Pane();
|
||||
ArrayList<Arc> pie = <span class="literal">new</span> ArrayList<Arc>();
|
||||
ArrayList<Text> pieDesc = <span class="literal">new</span> ArrayList<Text>();
|
||||
ArrayList<Group> layoutSlice = <span class="literal">new</span> ArrayList<Group>();
|
||||
<span class="literal">float</span>[] pieValues = {<span class="number">20.0f</span>, <span class="number">10.0f</span>, <span class="number">20.0f</span>, <span class="number">40.0f</span>, <span class="number">30.0f</span>}; <span class="comment">// First value controls the initial angle</span>
|
||||
String[] textValues = { <span class="string">"</span><span class="string">Quiz</span><span class="string">"</span>, <span class="string">"</span><span class="string">Project</span><span class="string">"</span>, <span class="string">"</span><span class="string">Final</span><span class="string">"</span>, <span class="string">"</span><span class="string">Midterm</span><span class="string">"</span>};
|
||||
<span class="literal">float</span>[][] textPos = { {<span class="number">165</span>, <span class="number">50</span>}, {<span class="number">70</span>, <span class="number">120</span>}, {<span class="number">150</span>, <span class="number">300</span>}, {<span class="number">250</span>, <span class="number">204</span>} }; <span class="comment">// I really didn't want to hard code the coords for the text, but JavaFX forced my hand</span>
|
||||
<span class="literal">int</span> j = <span class="number">1</span>;
|
||||
<span class="literal">float</span> startAngle = <span class="number">0.0f</span>;
|
||||
<span class="literal">final</span> <span class="literal">float</span> PIE_SIZE = <span class="number">200.0f</span>;
|
||||
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < <span class="number">4</span>; i++) {
|
||||
<span class="comment">// Arc</span>
|
||||
startAngle = startAngle + <span class="ST2">toDegrees</span>(pieValues[i]);
|
||||
System.<span class="ST3">out</span>.println(<span class="string">"</span><span class="string">i:</span><span class="string">"</span> + <span class="ST2">toDegrees</span>(pieValues[i]) + <span class="string">"</span><span class="string"> j: </span><span class="string">"</span> + <span class="ST2">toDegrees</span>(pieValues[j]));
|
||||
Arc pieSlice = <span class="literal">new</span> Arc();
|
||||
pieSlice.setCenterX(PIE_SIZE);
|
||||
pieSlice.setCenterY(PIE_SIZE);
|
||||
pieSlice.setRadiusX(PIE_SIZE);
|
||||
pieSlice.setRadiusY(PIE_SIZE);
|
||||
pieSlice.setStartAngle(startAngle); <span class="comment">//toDegrees(pieValues[i])</span>
|
||||
pieSlice.setLength(<span class="ST2">t</span><span class="ST2">oDegrees</span>(pieValues[j]));
|
||||
pieSlice.setType(ArcType.<span class="ST3">ROUND</span>);
|
||||
|
||||
<span class="comment">// Text</span>
|
||||
String descriptionString = textValues[i] + <span class="string">"</span><span class="string">--</span><span class="string">"</span> + pieValues[j] + <span class="string">"</span><span class="string">%</span><span class="string">"</span>;
|
||||
Text descText = <span class="literal">new</span> Text(textPos[i][<span class="number">0</span>], textPos[i][<span class="number">1</span>], descriptionString);
|
||||
|
||||
<span class="comment">// Add Arcs and text together into a Group</span>
|
||||
Group pieSliceStack = <span class="literal">new</span> Group();
|
||||
pieSliceStack.getChildren().addAll(pieSlice, descText);
|
||||
|
||||
<span class="comment">// Add Arc and text to respective ArrayLists</span>
|
||||
pie.add(pieSlice);
|
||||
pieDesc.add(descText);
|
||||
layoutSlice.add(pieSliceStack);
|
||||
|
||||
j++;
|
||||
}
|
||||
pie.get(<span class="number">0</span>).setFill(Color.<span class="ST3">BLUE</span>);
|
||||
pie.get(<span class="number">1</span>).setFill(Color.<span class="ST3">RED</span>);
|
||||
pie.get(<span class="number">2</span>).setFill(Color.<span class="ST3">YELLOW</span>);
|
||||
pie.get(<span class="number">3</span>).setFill(Color.<span class="ST3">GREEN</span>);
|
||||
|
||||
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">3</span>; i >= <span class="number">0</span>; i--) {
|
||||
pane.getChildren().add(layoutSlice.get(i));
|
||||
}
|
||||
|
||||
|
||||
Scene scene = <span class="literal">new</span> Scene(pane);
|
||||
primaryStage.setTitle(<span class="string">"</span><span class="string">Pie Chart</span><span class="string">"</span>);
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.show();
|
||||
|
||||
}
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> * </span><span class="comment">This</span> <span class="comment">function</span> <span class="comment">converts</span> <span class="comment">a</span> <span class="comment">value</span> <span class="comment">between</span><span class="comment"> 0 </span><span class="comment">and</span><span class="comment"> 100 </span><span class="comment">to</span> <span class="comment">a</span> <span class="comment">value</span> <span class="comment">between</span><span class="comment"> 0 </span><span class="comment">and</span><span class="comment"> 360, </span><span class="comment">while</span> <span class="comment">retaining</span> <span class="comment">the</span> <span class="comment">ratio</span> <span class="comment">between</span> <span class="comment">those</span> <span class="comment">two</span> <span class="comment">number</span> <span class="comment">values</span><span class="comment">.</span> <span class="comment">So</span> <span class="comment">for</span> <span class="comment">example</span><span class="comment">, 35 </span><span class="comment">turns</span> <span class="comment">into</span><span class="comment"> 90</span><span class="comment">.</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * </span><span class="comment">@param</span> <span class="ST4">oldValue</span>
|
||||
<span class="comment"> * </span><span class="comment">@return</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">float</span> <span class="ST5">toDegrees</span>(<span class="literal">float</span> oldValue) {
|
||||
<span class="literal">final</span> <span class="literal">float</span> oldMin = <span class="number">0</span>;
|
||||
<span class="literal">final</span> <span class="literal">float</span> oldMax = <span class="number">100</span>;
|
||||
<span class="literal">final</span> <span class="literal">float</span> newMin = <span class="number">0</span>;
|
||||
<span class="literal">final</span> <span class="literal">float</span> newMax = <span class="number">360</span>;
|
||||
<span class="literal">float</span> newValue = ((oldValue - oldMin) / (oldMax - oldMin)) * (newMax - newMin) + newMin;
|
||||
<span class="literal">return</span> Math.<span class="ST2">round</span>(newValue);
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST5">main</span>(String[] args) {
|
||||
<span class="ST2">launch</span>(args);
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
@ -0,0 +1,75 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>ThreeRandomCards.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}
|
||||
.string {color: #6a8759}
|
||||
.number {color: #6897bb}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/MP1_FX_CalebFontenot/src/mp1_fx_calebfontenot/ThreeRandomCards.java</td></tr></table>
|
||||
<pre>
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license</span>
|
||||
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="literal">package</span> mp1_fx_calebfontenot;
|
||||
|
||||
<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.image.Image;
|
||||
<span class="literal">import</span> javafx.scene.image.ImageView;
|
||||
<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> ThreeRandomCards <span class="literal">extends</span> Application {
|
||||
|
||||
@Override
|
||||
<span class="literal">public</span> <span class="literal">void</span> start(Stage primaryStage) <span class="literal">throws</span> Exception {
|
||||
GridPane pane = <span class="literal">new</span> GridPane();
|
||||
pane.setOnMouseClicked(e -> {
|
||||
addCards(pane);
|
||||
});
|
||||
System.out.println(<span class="string">"</span><span class="string">Created GridPane. Executing addCards() to add cards to GridPane.</span><span class="string">"</span>);
|
||||
addCards(pane);
|
||||
Scene scene = <span class="literal">new</span> Scene(pane);
|
||||
primaryStage.setTitle(<span class="string">"</span><span class="string">Three Random Cards</span><span class="string">"</span>);
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.show();
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">void</span> addCards(GridPane imagePane) {
|
||||
System.out.println(<span class="string">"</span><span class="string">addCards() executed!</span><span class="string">"</span>);
|
||||
imagePane.setAlignment(Pos.CENTER);
|
||||
imagePane.setHgap(<span class="number">5</span>);
|
||||
imagePane.setVgap(<span class="number">5</span>);
|
||||
<span class="comment">// Define Image objects</span>
|
||||
<span class="literal">int</span> rand = <span class="number">0</span>;
|
||||
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < <span class="number">3</span>; i++) {
|
||||
rand = (<span class="literal">int</span>) ((Math.random() * <span class="number">54</span>) + <span class="number">1</span>);
|
||||
imagePane.add(<span class="literal">new</span> ImageView(<span class="literal">new</span> Image(<span class="string">"</span><span class="string">https://files.calebfontenot.com/image/card/</span><span class="string">"</span> + rand + <span class="string">"</span><span class="string">.png</span><span class="string">"</span>)), i, <span class="number">0</span>);
|
||||
System.out.println(<span class="string">"</span><span class="string">added image </span><span class="string">"</span> + rand + <span class="string">"</span><span class="string"> to the imagePane.</span><span class="string">"</span>);
|
||||
}
|
||||
}
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
@ -0,0 +1,77 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>TicTacToe.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}
|
||||
.string {color: #6a8759}
|
||||
.number {color: #6897bb}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/MP1_FX_CalebFontenot/src/mp1_fx_calebfontenot/TicTacToe.java</td></tr></table>
|
||||
<pre>
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license</span>
|
||||
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="literal">package</span> mp1_fx_calebfontenot;
|
||||
|
||||
|
||||
<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.image.Image;
|
||||
<span class="literal">import</span> javafx.scene.image.ImageView;
|
||||
<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> TicTacToe <span class="literal">extends</span> Application {
|
||||
|
||||
@Override
|
||||
<span class="literal">public</span> <span class="literal">void</span> start(Stage primaryStage) <span class="literal">throws</span> Exception {
|
||||
<span class="literal">final</span> String BASE_URL = <span class="string">"</span><span class="string">https://files.calebfontenot.com/</span><span class="string">"</span>;
|
||||
Image imageX = <span class="literal">new</span> Image(BASE_URL + <span class="string">"</span><span class="string">image/x.gif</span><span class="string">"</span>);
|
||||
Image imageO = <span class="literal">new</span> Image(BASE_URL + <span class="string">"</span><span class="string">image/o.gif</span><span class="string">"</span>);
|
||||
|
||||
GridPane pane = <span class="literal">new</span> GridPane();
|
||||
pane.setAlignment(Pos.CENTER);
|
||||
pane.setHgap(<span class="number">5</span>);
|
||||
pane.setVgap(<span class="number">5</span>);
|
||||
|
||||
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < <span class="number">3</span>; i++) {
|
||||
<span class="literal">for</span> (<span class="literal">int</span> j = <span class="number">0</span>; j < <span class="number">3</span>; j++) {
|
||||
<span class="literal">int</span> status = (<span class="literal">int</span>) (Math.random() * <span class="number">3</span>);
|
||||
<span class="literal">if</span> (status == <span class="number">0</span>) {
|
||||
pane.add(<span class="literal">new</span> ImageView(imageX), j, i);
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (status == <span class="number">1</span>) {
|
||||
pane.add(<span class="literal">new</span> ImageView(imageO), j, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<span class="comment">// Create a scene and place it in the stage</span>
|
||||
Scene scene = <span class="literal">new</span> Scene(pane);
|
||||
primaryStage.setTitle(<span class="string">"</span><span class="string">Tic Tac Toe</span><span class="string">"</span>); <span class="comment">// Set the stage title</span>
|
||||
primaryStage.setScene(scene); <span class="comment">// Place the scene in the stage</span>
|
||||
primaryStage.show(); <span class="comment">// Display the stage</span>
|
||||
}
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
@ -116,7 +116,7 @@ manifest.file=manifest.mf
|
||||
meta.inf.dir=${src.dir}/META-INF
|
||||
mkdist.disabled=false
|
||||
native.bundling.enabled=false
|
||||
platform.active=JDK_1.8
|
||||
platform.active=JDK_8__System_
|
||||
run.classpath=\
|
||||
${dist.jar}:\
|
||||
${javac.classpath}:\
|
||||
|
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package mp1_fx_calebfontenot;
|
||||
|
||||
import static java.lang.Double.parseDouble;
|
||||
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.BorderPane;
|
||||
import javafx.scene.layout.FlowPane;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class Calculator extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
FlowPane pane = new FlowPane();
|
||||
pane.setHgap(2);
|
||||
TextField tfNumber1 = new TextField();
|
||||
TextField tfNumber2 = new TextField();
|
||||
TextField tfResult = new TextField();
|
||||
tfNumber1.setPrefColumnCount(3);
|
||||
tfNumber2.setPrefColumnCount(3);
|
||||
tfResult.setPrefColumnCount(3);
|
||||
|
||||
pane.getChildren().addAll(new Label("Number 1: "), tfNumber1, new Label("Number 2"), tfNumber2, new Label("Result: "), tfResult);
|
||||
|
||||
HBox hBox = new HBox(5);
|
||||
Button btAdd = new Button("Add");
|
||||
Button btSubtract = new Button("Subtract");
|
||||
Button btMultiply = new Button("Multiply");
|
||||
Button btDivide = new Button("Divide");
|
||||
hBox.setAlignment(Pos.CENTER);
|
||||
hBox.getChildren().addAll(btAdd, btSubtract, btMultiply, btDivide);
|
||||
|
||||
BorderPane borderPane = new BorderPane();
|
||||
borderPane.setCenter(pane);
|
||||
borderPane.setBottom(hBox);
|
||||
BorderPane.setAlignment(hBox, Pos.TOP_CENTER);
|
||||
|
||||
Scene scene = new Scene(borderPane, 250, 150);
|
||||
primaryStage.setTitle("Calculator");
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.show();
|
||||
|
||||
btAdd.setOnAction(e -> {
|
||||
tfResult.setText(Double.parseDouble(tfNumber1.getText())
|
||||
+ Double.parseDouble(tfNumber2.getText()) + "");
|
||||
});
|
||||
|
||||
btSubtract.setOnAction(e -> {
|
||||
tfResult.setText(Double.parseDouble(tfNumber1.getText())
|
||||
- Double.parseDouble(tfNumber2.getText()) + "");
|
||||
});
|
||||
|
||||
btMultiply.setOnAction(e -> {
|
||||
tfResult.setText(Double.parseDouble(tfNumber1.getText())
|
||||
* Double.parseDouble(tfNumber2.getText()) + "");
|
||||
});
|
||||
|
||||
btDivide.setOnAction(e -> {
|
||||
tfResult.setText(Double.parseDouble(tfNumber1.getText())
|
||||
/ Double.parseDouble(tfNumber2.getText()) + "");
|
||||
});
|
||||
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
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);
|
||||
// Round off
|
||||
// double scale = Math.pow(10, 2);
|
||||
//output = Math.round(output * scale) / scale;
|
||||
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);
|
||||
}
|
||||
}
|
@ -6,11 +6,15 @@ package mp1_fx_calebfontenot;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import javafx.application.Application;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Group;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Arc;
|
||||
import javafx.scene.shape.ArcType;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
/**
|
||||
@ -24,11 +28,16 @@ public class PieChart extends Application {
|
||||
// Create pane
|
||||
Pane pane = new Pane();
|
||||
ArrayList<Arc> pie = new ArrayList<Arc>();
|
||||
ArrayList<Text> pieDesc = new ArrayList<Text>();
|
||||
ArrayList<Group> layoutSlice = new ArrayList<Group>();
|
||||
float[] pieValues = {20.0f, 10.0f, 20.0f, 40.0f, 30.0f}; // First value controls the initial angle
|
||||
String[] textValues = { "Quiz", "Project", "Final", "Midterm"};
|
||||
float[][] textPos = { {165, 50}, {70, 120}, {150, 300}, {250, 204} }; // I really didn't want to hard code the coords for the text, but JavaFX forced my hand
|
||||
int j = 1;
|
||||
float startAngle = 0.0f;
|
||||
final float PIE_SIZE = 200.0f;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
// Arc
|
||||
startAngle = startAngle + toDegrees(pieValues[i]);
|
||||
System.out.println("i:" + toDegrees(pieValues[i]) + " j: " + toDegrees(pieValues[j]));
|
||||
Arc pieSlice = new Arc();
|
||||
@ -37,20 +46,34 @@ public class PieChart extends Application {
|
||||
pieSlice.setRadiusX(PIE_SIZE);
|
||||
pieSlice.setRadiusY(PIE_SIZE);
|
||||
pieSlice.setStartAngle(startAngle); //toDegrees(pieValues[i])
|
||||
pieSlice.setLength(toDegrees(pieValues[j++]));
|
||||
pieSlice.setLength(toDegrees(pieValues[j]));
|
||||
pieSlice.setType(ArcType.ROUND);
|
||||
|
||||
// Text
|
||||
String descriptionString = textValues[i] + "--" + pieValues[j] + "%";
|
||||
Text descText = new Text(textPos[i][0], textPos[i][1], descriptionString);
|
||||
|
||||
// Add Arcs and text together into a Group
|
||||
Group pieSliceStack = new Group();
|
||||
pieSliceStack.getChildren().addAll(pieSlice, descText);
|
||||
|
||||
// Add Arc and text to respective ArrayLists
|
||||
pie.add(pieSlice);
|
||||
pieDesc.add(descText);
|
||||
layoutSlice.add(pieSliceStack);
|
||||
|
||||
j++;
|
||||
}
|
||||
pie.get(0).setFill(Color.BLUE);
|
||||
pie.get(1).setFill(Color.RED);
|
||||
pie.get(2).setFill(Color.ORANGE);
|
||||
pie.get(3).setFill(Color.GREEN);
|
||||
|
||||
Object[] pieArr = pie.toArray();
|
||||
for (int i = 3; i >= 0; i--) {
|
||||
pane.getChildren().add((Arc) pieArr[i]);
|
||||
pane.getChildren().add(layoutSlice.get(i));
|
||||
}
|
||||
|
||||
|
||||
Scene scene = new Scene(pane);
|
||||
primaryStage.setTitle("Pie Chart");
|
||||
primaryStage.setScene(scene);
|
||||
@ -58,6 +81,12 @@ public class PieChart extends Application {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This function converts a value between 0 and 100 to a value between 0 and 360, while retaining the ratio between those two number values. So for example, 35 turns into 90.
|
||||
*
|
||||
* @param oldValue
|
||||
* @return
|
||||
*/
|
||||
public static float toDegrees(float oldValue) {
|
||||
final float oldMin = 0;
|
||||
final float oldMax = 100;
|
||||
|
@ -0,0 +1,137 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>RecursionDemo.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}
|
||||
.ST4 {font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST0 {color: #287bde}
|
||||
.number {color: #6897bb}
|
||||
.string {color: #6a8759}
|
||||
.ST1 {color: #808080; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST5 {color: #9876aa}
|
||||
.ST6 {color: #8a653b}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST3 {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/RecursionDemo/src/main/java/edu/slcc/asdv/caleb/recursiondemo/RecursionDemo.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"> */</span>
|
||||
<span class="literal">package</span> edu.slcc.asdv.caleb.recursiondemo;
|
||||
|
||||
<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> RecursionDemo {
|
||||
|
||||
<span class="literal">static</span> <span class="literal">void</span> <span class="ST1">printNTimes</span>(<span class="literal">int</span> nTimes, String message) {
|
||||
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < nTimes; ++i) {
|
||||
System.<span class="ST2">out</span>.println(message);
|
||||
}
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">boolean</span> <span class="ST3">isPalendrome</span>(String s) {
|
||||
String backwards = <span class="string">""</span>;
|
||||
<span class="literal">for</span> (<span class="literal">int</span> i = s.length() - <span class="number">1</span>; i >= <span class="number">0</span>; i--) {
|
||||
backwards += s.charAt(i);
|
||||
}
|
||||
<span class="literal">return</span> s.equals(backwards);
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">long</span> <span class="ST3">fib</span>(<span class="literal">int</span> n) {
|
||||
<span class="literal">if</span> (n == <span class="number">1</span> || n == <span class="number">2</span>) {
|
||||
<span class="literal">return</span> <span class="number">1</span>;
|
||||
}
|
||||
System.<span class="ST2">out</span>.println(n);
|
||||
<span class="literal">return</span> <span class="ST4">fib</span>(n - <span class="number">1</span>) + <span class="ST4">fib</span>(n - <span class="number">2</span>);
|
||||
}
|
||||
|
||||
<span class="literal">static</span> <span class="literal">void</span> <span class="ST1">printNTimesRecursion</span>(<span class="literal">int</span> nTimes, String message) {
|
||||
<span class="literal">if</span> (nTimes == <span class="number">0</span>) {
|
||||
<span class="literal">return</span>;
|
||||
}
|
||||
System.<span class="ST2">out</span>.println(message);
|
||||
<span class="ST4">printNTimesRecursion</span>(--nTimes, message);
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">boolean</span> <span class="ST3">isPalendromeRecursion</span>(String s) {
|
||||
<span class="literal">if</span> (s.length() == <span class="number">0</span> || s.length() == <span class="number">1</span>) {
|
||||
<span class="literal">return</span> <span class="literal">true</span>;
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (s.charAt(<span class="number">0</span>) != s.charAt(s.length() - <span class="number">1</span>)) {
|
||||
<span class="literal">return</span> <span class="literal">false</span>;
|
||||
}
|
||||
<span class="literal">return</span> <span class="ST4">isPalendromeRecursion</span>(s.substring(<span class="number">1</span>, s.length() - <span class="number">1</span>));
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">long</span> <span class="ST3">factorial</span>(<span class="literal">int</span> n) {
|
||||
<span class="literal">long</span> fact;
|
||||
<span class="literal">if</span> (n == <span class="number">1</span>) {
|
||||
<span class="literal">return</span> <span class="number">1</span>;
|
||||
}
|
||||
fact = n * <span class="ST4">factorial</span>(n - <span class="number">1</span>);
|
||||
<span class="literal">return</span> fact;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST3">printArrayRecursively</span>(<span class="literal">int</span>[] arr, <span class="literal">int</span> index) {
|
||||
<span class="literal">if</span> (index == arr.<span class="ST5">length</span>) {
|
||||
<span class="literal">return</span>;
|
||||
} <span class="literal">else</span> {
|
||||
System.<span class="ST2">out</span>.print(arr[index] + <span class="string">"</span> <span class="string">"</span>);
|
||||
<span class="ST4">printArrayRecursively</span>(arr, index + <span class="number">1</span>);
|
||||
}
|
||||
}
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * </span><span class="comment">@param</span> <span class="ST6">arr</span> <span class="comment">the</span> <span class="comment">array</span> <span class="comment">to</span> <span class="comment">be</span> <span class="comment">searched</span>
|
||||
<span class="comment"> * </span><span class="comment">@param</span> <span class="ST6">index</span> <span class="comment">the</span> <span class="comment">index</span> <span class="comment">of</span> <span class="comment">the</span> <span class="comment">array</span> <span class="comment">to</span> <span class="comment">manipulate</span>
|
||||
<span class="comment"> * </span><span class="comment">@param</span> <span class="ST6">currentMax</span> <span class="comment">the</span> <span class="comment">current</span> <span class="comment">maximum</span> <span class="comment">of</span> <span class="comment">the</span> <span class="comment">array</span>
|
||||
<span class="comment"> * </span><span class="comment">@return</span> <span class="comment">the</span> <span class="comment">maximum</span> <span class="comment">of</span> <span class="comment">the</span> <span class="comment">array</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">int</span> <span class="ST3">findMaximumRecursive</span>(<span class="literal">int</span> arr[], <span class="literal">int</span> index, <span class="literal">int</span> currentMax) <span class="literal">throws</span> Exception {
|
||||
<span class="comment">//System.out.println("at index " + index);</span>
|
||||
<span class="literal">if</span> (index >= (arr.<span class="ST5">length</span>)) {
|
||||
<span class="comment">//throw new ArrayIndexOutOfBoundsException();</span>
|
||||
<span class="literal">return</span> currentMax;
|
||||
}
|
||||
<span class="literal">if</span> (arr[index] >= currentMax) {
|
||||
currentMax = arr[index];
|
||||
}
|
||||
currentMax = <span class="ST4">findMaximumRecursive</span>(arr, (index + <span class="number">1</span>), currentMax);
|
||||
<span class="literal">return</span> currentMax;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">int</span> <span class="ST3">findMaximumRecursive</span>(<span class="literal">int</span> arr[]) <span class="literal">throws</span> Exception {
|
||||
<span class="comment">// This method simply makes it possible to call findMaximumRecursive() without giving it currentMax or an index</span>
|
||||
<span class="literal">return</span> <span class="ST4">findMaximumRecursive</span>(arr, <span class="number">0</span>, Integer.<span class="ST2">MIN_VALUE</span>);
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST3">main</span>(String[] args) <span class="literal">throws</span> Exception {
|
||||
<span class="comment">//System.out.println(factorial(20));</span>
|
||||
<span class="comment">//printNTimesRecursion(1, "Hello Recursion");</span>
|
||||
<span class="comment">//System.out.println(fib(10));</span>
|
||||
<span class="comment">//System.out.println(isPalendrome("detartrated"));</span>
|
||||
<span class="comment">//System.out.println(isPalendromeRecursion("detartrated"));</span>
|
||||
<span class="comment">//int[] arr = {2, 3, 5, 6, 7, 8, 10, 32, 64, 128};</span>
|
||||
<span class="comment">//printArrayRecursively(arr, 0);</span>
|
||||
System.<span class="ST2">out</span>.println(<span class="ST4">f</span><span class="ST4">indMaximumRecursive</span>(<span class="literal">new</span> <span class="literal">int</span>[]{<span class="number">99</span>, <span class="number">1</span>, <span class="number">44</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">55</span>}));
|
||||
System.<span class="ST2">out</span>.println(<span class="ST4">f</span><span class="ST4">indMaximumRecursive</span>(<span class="literal">new</span> <span class="literal">int</span>[]{<span class="number">1</span>, <span class="number">44</span>, <span class="number">2</span>, <span class="number">3</span>}));
|
||||
System.<span class="ST2">out</span>.println(<span class="ST4">f</span><span class="ST4">indMaximumRecursive</span>(<span class="literal">new</span> <span class="literal">int</span>[]{<span class="number">1</span>, <span class="number">44</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">300</span>}));
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
18
Semester 3/Assignments/RecursionDemo/nb-configuration.xml
Normal file
18
Semester 3/Assignments/RecursionDemo/nb-configuration.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project-shared-configuration>
|
||||
<!--
|
||||
This file contains additional configuration written by modules in the NetBeans IDE.
|
||||
The configuration is intended to be shared among all the users of project and
|
||||
therefore it is assumed to be part of version control checkout.
|
||||
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
|
||||
-->
|
||||
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
|
||||
<!--
|
||||
Properties that influence various parts of the IDE, especially code formatting and the like.
|
||||
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
|
||||
That way multiple projects can share the same settings (useful for formatting rules for example).
|
||||
Any value defined here will override the pom.xml file value but is only applicable to the current project.
|
||||
-->
|
||||
<netbeans.hint.jdkPlatform>JDK_20</netbeans.hint.jdkPlatform>
|
||||
</properties>
|
||||
</project-shared-configuration>
|
@ -9,15 +9,13 @@ package edu.slcc.asdv.caleb.recursiondemo;
|
||||
*/
|
||||
public class RecursionDemo {
|
||||
|
||||
static void printNTimes(int nTimes, String message)
|
||||
{
|
||||
static void printNTimes(int nTimes, String message) {
|
||||
for (int i = 0; i < nTimes; ++i) {
|
||||
System.out.println(message);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isPalendrome(String s)
|
||||
{
|
||||
public static boolean isPalendrome(String s) {
|
||||
String backwards = "";
|
||||
for (int i = s.length() - 1; i >= 0; i--) {
|
||||
backwards += s.charAt(i);
|
||||
@ -25,8 +23,7 @@ public class RecursionDemo {
|
||||
return s.equals(backwards);
|
||||
}
|
||||
|
||||
public static long fib(int n)
|
||||
{
|
||||
public static long fib(int n) {
|
||||
if (n == 1 || n == 2) {
|
||||
return 1;
|
||||
}
|
||||
@ -34,8 +31,7 @@ public class RecursionDemo {
|
||||
return fib(n - 1) + fib(n - 2);
|
||||
}
|
||||
|
||||
static void printNTimesRecursion(int nTimes, String message)
|
||||
{
|
||||
static void printNTimesRecursion(int nTimes, String message) {
|
||||
if (nTimes == 0) {
|
||||
return;
|
||||
}
|
||||
@ -51,9 +47,8 @@ public class RecursionDemo {
|
||||
}
|
||||
return isPalendromeRecursion(s.substring(1, s.length() - 1));
|
||||
}
|
||||
|
||||
public static long factorial(int n)
|
||||
{
|
||||
|
||||
public static long factorial(int n) {
|
||||
long fact;
|
||||
if (n == 1) {
|
||||
return 1;
|
||||
@ -61,24 +56,51 @@ public class RecursionDemo {
|
||||
fact = n * factorial(n - 1);
|
||||
return fact;
|
||||
}
|
||||
|
||||
|
||||
public static void printArrayRecursively(int[] arr, int index) {
|
||||
if (index == arr.length) {
|
||||
return;
|
||||
} else {
|
||||
System.out.print(arr[index] + " ");
|
||||
printArrayRecursively(arr, index+1);
|
||||
printArrayRecursively(arr, index + 1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
System.out.println(factorial(20));
|
||||
printNTimesRecursion(1, "Hello Recursion");
|
||||
/**
|
||||
*
|
||||
* @param arr the array to be searched
|
||||
* @param index the index of the array to manipulate
|
||||
* @param currentMax the current maximum of the array
|
||||
* @return the maximum of the array
|
||||
*/
|
||||
public static int findMaximumRecursive(int arr[], int index, int currentMax) throws Exception {
|
||||
//System.out.println("at index " + index);
|
||||
if (index >= (arr.length)) {
|
||||
//throw new ArrayIndexOutOfBoundsException();
|
||||
return currentMax;
|
||||
}
|
||||
if (arr[index] >= currentMax) {
|
||||
currentMax = arr[index];
|
||||
}
|
||||
currentMax = findMaximumRecursive(arr, (index + 1), currentMax);
|
||||
return currentMax;
|
||||
}
|
||||
|
||||
public static int findMaximumRecursive(int arr[]) throws Exception {
|
||||
// This method simply makes it possible to call findMaximumRecursive() without giving it currentMax or an index
|
||||
return findMaximumRecursive(arr, 0, Integer.MIN_VALUE);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
//System.out.println(factorial(20));
|
||||
//printNTimesRecursion(1, "Hello Recursion");
|
||||
//System.out.println(fib(10));
|
||||
System.out.println(isPalendrome("detartrated"));
|
||||
System.out.println(isPalendromeRecursion("detartrated"));
|
||||
int[] arr = {2, 3, 5, 6, 7, 8, 10, 32, 64, 128};
|
||||
printArrayRecursively(arr, 0);
|
||||
//System.out.println(isPalendrome("detartrated"));
|
||||
//System.out.println(isPalendromeRecursion("detartrated"));
|
||||
//int[] arr = {2, 3, 5, 6, 7, 8, 10, 32, 64, 128};
|
||||
//printArrayRecursively(arr, 0);
|
||||
System.out.println(findMaximumRecursive(new int[]{99, 1, 44, 2, 3, 55}));
|
||||
System.out.println(findMaximumRecursive(new int[]{1, 44, 2, 3}));
|
||||
System.out.println(findMaximumRecursive(new int[]{1, 44, 2, 3, 300}));
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
@ -1 +1 @@
|
||||
/home/caleb/ASDV-WebDev/Semester 2/RecursionDemo/src/main/java/edu/slcc/asdv/caleb/recursiondemo/RecursionDemo.java
|
||||
/home/caleb/ASDV-Java/Semester 3/Assignments/RecursionDemo/src/main/java/edu/slcc/asdv/caleb/recursiondemo/RecursionDemo.java
|
||||
|
@ -0,0 +1,84 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>BallControl.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}
|
||||
.number {color: #6897bb}
|
||||
.string {color: #6a8759}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/lab3_CalebFontenot/src/lab3_calebfontenot/BallControl.java</td></tr></table>
|
||||
<pre>
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license</span>
|
||||
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="literal">package</span> lab3_calebfontenot;
|
||||
|
||||
<span class="literal">import</span> javafx.application.Application;
|
||||
<span class="literal">import</span> javafx.event.EventHandler;
|
||||
<span class="literal">import</span> javafx.scene.Scene;
|
||||
<span class="literal">import</span> javafx.scene.input.KeyCode;
|
||||
<span class="literal">import</span> javafx.scene.input.MouseEvent;
|
||||
<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> BallControl <span class="literal">extends</span> Application {
|
||||
|
||||
@Override
|
||||
<span class="literal">public</span> <span class="literal">void</span> start(Stage primaryStage) <span class="literal">throws</span> Exception {
|
||||
BouncingBall bouncingBall = <span class="literal">new</span> BouncingBall();
|
||||
<span class="comment">// Create a scene and place it in the stage</span>
|
||||
Scene scene = <span class="literal">new</span> Scene(bouncingBall, <span class="number">800</span>, <span class="number">600</span>);
|
||||
primaryStage.setTitle(<span class="string">"</span><span class="string">Bouncing Ball Control</span><span class="string">"</span>);
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.show();
|
||||
bouncingBall.requestFocus();
|
||||
|
||||
bouncingBall.setOnMousePressed(<span class="literal">new</span> EventHandler<MouseEvent>() {
|
||||
@Override
|
||||
<span class="literal">public</span> <span class="literal">void</span> handle(MouseEvent event) {
|
||||
bouncingBall.pause();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
bouncingBall.setOnMouseReleased(e
|
||||
-> {
|
||||
bouncingBall.play();
|
||||
});
|
||||
|
||||
<span class="comment">// Increase and decrease animation</span>
|
||||
|
||||
bouncingBall.setOnKeyPressed (e
|
||||
-> {
|
||||
<span class="literal">if</span> (e.getCode() == KeyCode.UP) {
|
||||
bouncingBall.increaseSpeed();
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (e.getCode() == KeyCode.DOWN) {
|
||||
bouncingBall.decreaseSpeed();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
);
|
||||
}
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
@ -0,0 +1,108 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>BouncingBall.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}
|
||||
.number {color: #6897bb}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/lab3_CalebFontenot/src/lab3_calebfontenot/BouncingBall.java</td></tr></table>
|
||||
<pre>
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license</span>
|
||||
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="literal">package</span> lab3_calebfontenot;
|
||||
|
||||
<span class="literal">import</span> javafx.animation.KeyFrame;
|
||||
<span class="literal">import</span> javafx.animation.Timeline;
|
||||
<span class="literal">import</span> <span class="literal">static</span> javafx.application.Application.launch;
|
||||
<span class="literal">import</span> javafx.beans.property.DoubleProperty;
|
||||
<span class="literal">import</span> javafx.event.ActionEvent;
|
||||
<span class="literal">import</span> javafx.event.EventHandler;
|
||||
<span class="literal">import</span> javafx.scene.layout.Pane;
|
||||
<span class="literal">import</span> javafx.scene.paint.Color;
|
||||
<span class="literal">import</span> javafx.scene.shape.Circle;
|
||||
<span class="literal">import</span> javafx.util.Duration;
|
||||
|
||||
<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> BouncingBall <span class="literal">extends</span> Pane {
|
||||
|
||||
<span class="literal">final</span> <span class="literal">double</span> radius = <span class="number">20</span>;
|
||||
<span class="literal">private</span> <span class="literal">double</span> x = radius, y = radius;
|
||||
<span class="literal">private</span> <span class="literal">double</span> dx = <span class="number">1</span>, dy = <span class="number">1</span>;
|
||||
<span class="literal">private</span> Circle circle = <span class="literal">new</span> Circle(x, y, radius);
|
||||
<span class="literal">private</span> Timeline animation;
|
||||
|
||||
<span class="literal">public</span> BouncingBall()
|
||||
{
|
||||
circle.setFill(Color.BROWN); <span class="comment">// Set ball color</span>
|
||||
getChildren().add(circle); <span class="comment">// Place a ball into this pane</span>
|
||||
|
||||
<span class="comment">// Create an animation for moving the ball</span>
|
||||
animation = <span class="literal">new</span> Timeline(<span class="literal">new</span> KeyFrame(Duration.millis(<span class="number">1</span>), <span class="literal">new</span> EventHandler<ActionEvent>() {
|
||||
@Override
|
||||
<span class="literal">public</span> <span class="literal">void</span> handle(ActionEvent t)
|
||||
{
|
||||
moveBall();
|
||||
}
|
||||
})
|
||||
);
|
||||
animation.setRate(animation.getRate() * <span class="number">20</span>);
|
||||
animation.setCycleCount(Timeline.INDEFINITE);
|
||||
animation.play();
|
||||
}
|
||||
|
||||
<span class="literal">private</span> <span class="literal">void</span> moveBall() {
|
||||
<span class="comment">// Check boundaries</span>
|
||||
<span class="literal">if</span> (x < radius || x > getWidth() - radius) {
|
||||
dx *= -<span class="number">1</span>; <span class="comment">// Change ball move direction</span>
|
||||
}
|
||||
<span class="literal">if</span> (y < radius || y > getHeight() - radius) {
|
||||
dy *= -<span class="number">1</span>; <span class="comment">// Change ball move direction</span>
|
||||
}
|
||||
|
||||
<span class="comment">// Adjust ball position by 1 or -1</span>
|
||||
x += dx;
|
||||
y += dy;
|
||||
circle.setCenterX(x);
|
||||
circle.setCenterY(y);
|
||||
}
|
||||
<span class="literal">public</span> <span class="literal">void</span> play() {
|
||||
animation.play();
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">void</span> pause() {
|
||||
animation.pause();
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">void</span> increaseSpeed() {
|
||||
animation.setRate(animation.getRate() * <span class="number">1.5</span>);
|
||||
System.out.println(animation.getRate());
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">void</span> decreaseSpeed() {
|
||||
animation.setRate(animation.getRate() * <span class="number">1.5</span> > <span class="number">0</span> ? animation.getRate() / <span class="number">1.5</span> : <span class="number">0</span>);
|
||||
System.out.println(animation.getRate());
|
||||
}
|
||||
|
||||
<span class="literal">public</span> DoubleProperty rateProperty() {
|
||||
<span class="literal">return</span> animation.rateProperty();
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
@ -2,8 +2,6 @@
|
||||
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
|
||||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
|
||||
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
|
||||
<group>
|
||||
<file>file:/home/caleb/ASDV-Java/Semester%203/Assignments/lab3_CalebFontenot/src/lab3_calebfontenot/BallControl.java</file>
|
||||
</group>
|
||||
<group/>
|
||||
</open-files>
|
||||
</project-private>
|
||||
|
BIN
Semester 3/ZIPs/MP1_FX_CalebFontenot.zip
Normal file
BIN
Semester 3/ZIPs/MP1_FX_CalebFontenot.zip
Normal file
Binary file not shown.
BIN
Semester 3/ZIPs/lab3_CalebFontenot.zip
Normal file
BIN
Semester 3/ZIPs/lab3_CalebFontenot.zip
Normal file
Binary file not shown.
BIN
Semester 3/ZIPs/lab4_Recursion1_CalebFontenot.zip
Normal file
BIN
Semester 3/ZIPs/lab4_Recursion1_CalebFontenot.zip
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user