diff --git a/.gitignore b/.gitignore index 379bd6e..18fca13 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ diff --git a/Semester 3/Assignments/MP1_FX_CalebFontenot/Printed HTMLs/BarChart.html b/Semester 3/Assignments/MP1_FX_CalebFontenot/Printed HTMLs/BarChart.html new file mode 100644 index 0000000..b31e724 --- /dev/null +++ b/Semester 3/Assignments/MP1_FX_CalebFontenot/Printed HTMLs/BarChart.html @@ -0,0 +1,85 @@ + + + +BarChart.java + + + + +
/home/caleb/ASDV-Java/Semester 3/Assignments/MP1_FX_CalebFontenot/src/mp1_fx_calebfontenot/BarChart.java
+
+/*
+ * 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 javafx.application.Application;
+import javafx.scene.Scene;
+import javafx.scene.layout.Pane;
+import javafx.scene.paint.Color;
+import javafx.scene.shape.Rectangle;
+import javafx.scene.text.Text;
+import javafx.stage.Stage;
+
+/**
+ *
+ * @author caleb
+ */
+public class BarChart extends Application {
+
+    @Override
+    public void start(Stage primaryStage) throws Exception {
+        Pane pane = new Pane();
+        
+        double height = 300;
+        double panelHeight = 150;
+        Rectangle r1 = new Rectangle(10, panelHeight - height * 0.2, 100, height * 0.2);
+        r1.setFill(Color.RED);
+        Text text1 = new Text(10, panelHeight - height * 0.2 - 10, "Project -- 20%");
+        
+        Rectangle r2 = new Rectangle(10 + 110, panelHeight - height * 0.1, 100, height * 0.1);
+        r2.setFill(Color.BLUE);
+        Text text2 = new Text(10 + 110, panelHeight - height * 0.1 - 10, "Quiz -- 10%");
+        
+        Rectangle r3 = new Rectangle(10 + 220, panelHeight - height * 0.3, 100, height * 0.3);
+        r3.setFill(Color.GREEN);
+        Text text3 = new Text(10 + 220, panelHeight - height * 0.3 - 10, "Midterm -- 30%");
+        
+        Rectangle r4 = new Rectangle(10 + 330, panelHeight - height * 0.4, 100, height * 0.4);
+        r4.setFill(Color.ORANGE);
+        Text text4 = new Text(10 + 330, panelHeight - height * 0.4 - 10, "Final -- 40%");
+        
+        pane.getChildren().addAll(r1, text1, r2, text2, r3, text3, r4, text4);
+        
+        // Create a scene and place it in the stage
+        Scene scene = new Scene(pane, 500, panelHeight);
+        primaryStage.setTitle("Bar Chart");
+        primaryStage.setScene(scene);
+        primaryStage.show();
+        
+    }
+    public static void main(String[] args) {
+        launch(args);
+    }
+    
+}
+
+
+ diff --git a/Semester 3/Assignments/MP1_FX_CalebFontenot/Printed HTMLs/Calculator.html b/Semester 3/Assignments/MP1_FX_CalebFontenot/Printed HTMLs/Calculator.html new file mode 100644 index 0000000..e6d645f --- /dev/null +++ b/Semester 3/Assignments/MP1_FX_CalebFontenot/Printed HTMLs/Calculator.html @@ -0,0 +1,109 @@ + + + +Calculator.java + + + + +
/home/caleb/ASDV-Java/Semester 3/Assignments/MP1_FX_CalebFontenot/src/mp1_fx_calebfontenot/Calculator.java
+
+/*
+ * 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);
+    }
+}
+
+
+ diff --git a/Semester 3/Assignments/MP1_FX_CalebFontenot/Printed HTMLs/Investment.html b/Semester 3/Assignments/MP1_FX_CalebFontenot/Printed HTMLs/Investment.html new file mode 100644 index 0000000..0cc931e --- /dev/null +++ b/Semester 3/Assignments/MP1_FX_CalebFontenot/Printed HTMLs/Investment.html @@ -0,0 +1,97 @@ + + + +Investment.java + + + + +
/home/caleb/ASDV-Java/Semester 3/Assignments/MP1_FX_CalebFontenot/src/mp1_fx_calebfontenot/Investment.java
+
+/*
+ * 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);
+    }
+}
+
+
+ diff --git a/Semester 3/Assignments/MP1_FX_CalebFontenot/Printed HTMLs/PieChart.html b/Semester 3/Assignments/MP1_FX_CalebFontenot/Printed HTMLs/PieChart.html new file mode 100644 index 0000000..4bd40ee --- /dev/null +++ b/Semester 3/Assignments/MP1_FX_CalebFontenot/Printed HTMLs/PieChart.html @@ -0,0 +1,132 @@ + + + +PieChart.java + + + + +
/home/caleb/ASDV-Java/Semester 3/Assignments/MP1_FX_CalebFontenot/src/mp1_fx_calebfontenot/PieChart.java
+
+/*
+ * 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.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;
+
+/**
+ *
+ * @author caleb
+ */
+public class PieChart extends Application {
+
+    @Override
+    public void start(Stage primaryStage) throws Exception {
+        // 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();
+            pieSlice.setCenterX(PIE_SIZE);
+            pieSlice.setCenterY(PIE_SIZE);
+            pieSlice.setRadiusX(PIE_SIZE);
+            pieSlice.setRadiusY(PIE_SIZE);
+            pieSlice.setStartAngle(startAngle); //toDegrees(pieValues[i])
+            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.YELLOW);
+        pie.get(3).setFill(Color.GREEN);
+
+        for (int i = 3; i >= 0; i--) {
+            pane.getChildren().add(layoutSlice.get(i));
+        }
+
+        
+        Scene scene = new Scene(pane);
+        primaryStage.setTitle("Pie Chart");
+        primaryStage.setScene(scene);
+        primaryStage.show();
+
+    }
+
+    /**
+     * 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;
+        final float newMin = 0;
+        final float newMax = 360;
+        float newValue = ((oldValue - oldMin) / (oldMax - oldMin)) * (newMax - newMin) + newMin;
+        return Math.round(newValue);
+    }
+
+    public static void main(String[] args) {
+        launch(args);
+    }
+}
+
+
+ diff --git a/Semester 3/Assignments/MP1_FX_CalebFontenot/Printed HTMLs/ThreeRandomCards.html b/Semester 3/Assignments/MP1_FX_CalebFontenot/Printed HTMLs/ThreeRandomCards.html new file mode 100644 index 0000000..d8b4b50 --- /dev/null +++ b/Semester 3/Assignments/MP1_FX_CalebFontenot/Printed HTMLs/ThreeRandomCards.html @@ -0,0 +1,75 @@ + + + +ThreeRandomCards.java + + + + +
/home/caleb/ASDV-Java/Semester 3/Assignments/MP1_FX_CalebFontenot/src/mp1_fx_calebfontenot/ThreeRandomCards.java
+
+/*
+ * 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 javafx.application.Application;
+import javafx.geometry.Pos;
+import javafx.scene.Scene;
+import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
+import javafx.scene.layout.GridPane;
+import javafx.stage.Stage;
+
+/**
+ *
+ * @author caleb
+ */
+public class ThreeRandomCards extends Application {
+
+    @Override
+    public void start(Stage primaryStage) throws Exception {
+        GridPane pane = new GridPane();
+        pane.setOnMouseClicked(e -> {
+            addCards(pane);
+        });
+        System.out.println("Created GridPane. Executing addCards() to add cards to GridPane.");
+        addCards(pane);
+        Scene scene = new Scene(pane);
+        primaryStage.setTitle("Three Random Cards");
+        primaryStage.setScene(scene);
+        primaryStage.show();
+    }
+
+    public void addCards(GridPane imagePane) {
+        System.out.println("addCards() executed!");
+        imagePane.setAlignment(Pos.CENTER);
+        imagePane.setHgap(5);
+        imagePane.setVgap(5);
+        // Define Image objects
+        int rand = 0;
+        for (int i = 0; i < 3; i++) {
+            rand = (int) ((Math.random() * 54) + 1);
+            imagePane.add(new ImageView(new Image("https://files.calebfontenot.com/image/card/" + rand + ".png")), i, 0);
+            System.out.println("added image " + rand + " to the imagePane.");
+        }
+    }
+    public static void main(String[] args) {
+        launch(args);
+    }
+}
+
+
+ diff --git a/Semester 3/Assignments/MP1_FX_CalebFontenot/Printed HTMLs/TicTacToe.html b/Semester 3/Assignments/MP1_FX_CalebFontenot/Printed HTMLs/TicTacToe.html new file mode 100644 index 0000000..c310ee0 --- /dev/null +++ b/Semester 3/Assignments/MP1_FX_CalebFontenot/Printed HTMLs/TicTacToe.html @@ -0,0 +1,77 @@ + + + +TicTacToe.java + + + + +
/home/caleb/ASDV-Java/Semester 3/Assignments/MP1_FX_CalebFontenot/src/mp1_fx_calebfontenot/TicTacToe.java
+
+/*
+ * 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 javafx.application.Application;
+import javafx.geometry.Pos;
+import javafx.scene.Scene;
+import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
+import javafx.scene.layout.GridPane;
+import javafx.stage.Stage;
+
+/**
+ *
+ * @author caleb
+ */
+public class TicTacToe extends Application {
+
+    @Override
+    public void start(Stage primaryStage) throws Exception {
+        final String BASE_URL = "https://files.calebfontenot.com/";
+        Image imageX = new Image(BASE_URL + "image/x.gif");
+        Image imageO = new Image(BASE_URL + "image/o.gif");
+
+        GridPane pane = new GridPane();
+        pane.setAlignment(Pos.CENTER);
+        pane.setHgap(5);
+        pane.setVgap(5);
+
+        for (int i = 0; i < 3; i++) {
+            for (int j = 0; j < 3; j++) {
+                int status = (int) (Math.random() * 3);
+                if (status == 0) {
+                    pane.add(new ImageView(imageX), j, i);
+                } else if (status == 1) {
+                    pane.add(new ImageView(imageO), j, i);
+                }
+            }
+        }
+        
+        // Create a scene and place it in the stage
+        Scene scene = new Scene(pane);
+        primaryStage.setTitle("Tic Tac Toe"); // Set the stage title
+        primaryStage.setScene(scene); // Place the scene in the stage
+        primaryStage.show(); // Display the stage
+    }
+    public static void main(String[] args) {
+        launch(args);
+    }
+}
+
+
+ diff --git a/Semester 3/Assignments/MP1_FX_CalebFontenot/nbproject/project.properties b/Semester 3/Assignments/MP1_FX_CalebFontenot/nbproject/project.properties index 0a20097..5743833 100644 --- a/Semester 3/Assignments/MP1_FX_CalebFontenot/nbproject/project.properties +++ b/Semester 3/Assignments/MP1_FX_CalebFontenot/nbproject/project.properties @@ -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}:\ diff --git a/Semester 3/Assignments/MP1_FX_CalebFontenot/src/mp1_fx_calebfontenot/Calculator.java b/Semester 3/Assignments/MP1_FX_CalebFontenot/src/mp1_fx_calebfontenot/Calculator.java new file mode 100644 index 0000000..473286f --- /dev/null +++ b/Semester 3/Assignments/MP1_FX_CalebFontenot/src/mp1_fx_calebfontenot/Calculator.java @@ -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); + } +} diff --git a/Semester 3/Assignments/MP1_FX_CalebFontenot/src/mp1_fx_calebfontenot/Investment.java b/Semester 3/Assignments/MP1_FX_CalebFontenot/src/mp1_fx_calebfontenot/Investment.java new file mode 100644 index 0000000..6d3e85a --- /dev/null +++ b/Semester 3/Assignments/MP1_FX_CalebFontenot/src/mp1_fx_calebfontenot/Investment.java @@ -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); + } +} diff --git a/Semester 3/Assignments/MP1_FX_CalebFontenot/src/mp1_fx_calebfontenot/PieChart.java b/Semester 3/Assignments/MP1_FX_CalebFontenot/src/mp1_fx_calebfontenot/PieChart.java index 1f7862d..3a735b0 100644 --- a/Semester 3/Assignments/MP1_FX_CalebFontenot/src/mp1_fx_calebfontenot/PieChart.java +++ b/Semester 3/Assignments/MP1_FX_CalebFontenot/src/mp1_fx_calebfontenot/PieChart.java @@ -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 pie = new ArrayList(); + ArrayList pieDesc = new ArrayList(); + ArrayList layoutSlice = new ArrayList(); 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; diff --git a/Semester 3/Assignments/RecursionDemo/lab4_Recursion1_CalebFontenot.html b/Semester 3/Assignments/RecursionDemo/lab4_Recursion1_CalebFontenot.html new file mode 100644 index 0000000..7f5dca4 --- /dev/null +++ b/Semester 3/Assignments/RecursionDemo/lab4_Recursion1_CalebFontenot.html @@ -0,0 +1,137 @@ + + + +RecursionDemo.java + + + + +
/home/caleb/ASDV-Java/Semester 3/Assignments/RecursionDemo/src/main/java/edu/slcc/asdv/caleb/recursiondemo/RecursionDemo.java
+
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ */
+package edu.slcc.asdv.caleb.recursiondemo;
+
+/**
+ *
+ * @author caleb
+ */
+public class RecursionDemo {
+
+    static void printNTimes(int nTimes, String message) {
+        for (int i = 0; i < nTimes; ++i) {
+            System.out.println(message);
+        }
+    }
+
+    public static boolean isPalendrome(String s) {
+        String backwards = "";
+        for (int i = s.length() - 1; i >= 0; i--) {
+            backwards += s.charAt(i);
+        }
+        return s.equals(backwards);
+    }
+
+    public static long fib(int n) {
+        if (n == 1 || n == 2) {
+            return 1;
+        }
+        System.out.println(n);
+        return fib(n - 1) + fib(n - 2);
+    }
+
+    static void printNTimesRecursion(int nTimes, String message) {
+        if (nTimes == 0) {
+            return;
+        }
+        System.out.println(message);
+        printNTimesRecursion(--nTimes, message);
+    }
+
+    public static boolean isPalendromeRecursion(String s) {
+        if (s.length() == 0 || s.length() == 1) {
+            return true;
+        } else if (s.charAt(0) != s.charAt(s.length() - 1)) {
+            return false;
+        }
+        return isPalendromeRecursion(s.substring(1, s.length() - 1));
+    }
+
+    public static long factorial(int n) {
+        long fact;
+        if (n == 1) {
+            return 1;
+        }
+        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);
+        }
+    }
+
+    /**
+     *
+     * @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(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}));
+    }
+}
+
+
+ diff --git a/Semester 3/Assignments/RecursionDemo/nb-configuration.xml b/Semester 3/Assignments/RecursionDemo/nb-configuration.xml new file mode 100644 index 0000000..9c74157 --- /dev/null +++ b/Semester 3/Assignments/RecursionDemo/nb-configuration.xml @@ -0,0 +1,18 @@ + + + + + + JDK_20 + + diff --git a/Semester 3/Assignments/RecursionDemo/src/main/java/edu/slcc/asdv/caleb/recursiondemo/RecursionDemo.java b/Semester 3/Assignments/RecursionDemo/src/main/java/edu/slcc/asdv/caleb/recursiondemo/RecursionDemo.java index 352c17a..d8cbbff 100644 --- a/Semester 3/Assignments/RecursionDemo/src/main/java/edu/slcc/asdv/caleb/recursiondemo/RecursionDemo.java +++ b/Semester 3/Assignments/RecursionDemo/src/main/java/edu/slcc/asdv/caleb/recursiondemo/RecursionDemo.java @@ -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})); } } diff --git a/Semester 3/Assignments/RecursionDemo/target/classes/edu/slcc/asdv/caleb/recursiondemo/RecursionDemo.class b/Semester 3/Assignments/RecursionDemo/target/classes/edu/slcc/asdv/caleb/recursiondemo/RecursionDemo.class index 45f3b40..a731077 100644 Binary files a/Semester 3/Assignments/RecursionDemo/target/classes/edu/slcc/asdv/caleb/recursiondemo/RecursionDemo.class and b/Semester 3/Assignments/RecursionDemo/target/classes/edu/slcc/asdv/caleb/recursiondemo/RecursionDemo.class differ diff --git a/Semester 3/Assignments/RecursionDemo/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/Semester 3/Assignments/RecursionDemo/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst index 7972ded..acb388c 100644 --- a/Semester 3/Assignments/RecursionDemo/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst +++ b/Semester 3/Assignments/RecursionDemo/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -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 diff --git a/Semester 3/Assignments/lab3_CalebFontenot/PrintedHTMLs/BallControl.html b/Semester 3/Assignments/lab3_CalebFontenot/PrintedHTMLs/BallControl.html new file mode 100644 index 0000000..755166b --- /dev/null +++ b/Semester 3/Assignments/lab3_CalebFontenot/PrintedHTMLs/BallControl.html @@ -0,0 +1,84 @@ + + + +BallControl.java + + + + +
/home/caleb/ASDV-Java/Semester 3/Assignments/lab3_CalebFontenot/src/lab3_calebfontenot/BallControl.java
+
+/*
+ * 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 lab3_calebfontenot;
+
+import javafx.application.Application;
+import javafx.event.EventHandler;
+import javafx.scene.Scene;
+import javafx.scene.input.KeyCode;
+import javafx.scene.input.MouseEvent;
+import javafx.stage.Stage;
+
+/**
+ *
+ * @author caleb
+ */
+public class BallControl extends Application {
+
+    @Override
+    public void start(Stage primaryStage) throws Exception {
+        BouncingBall bouncingBall = new BouncingBall();
+        // Create a scene and place it in the stage
+        Scene scene = new Scene(bouncingBall, 800, 600);
+        primaryStage.setTitle("Bouncing Ball Control");
+        primaryStage.setScene(scene);
+        primaryStage.show();
+        bouncingBall.requestFocus();
+
+        bouncingBall.setOnMousePressed(new EventHandler<MouseEvent>() {
+            @Override
+            public void handle(MouseEvent event) {
+                bouncingBall.pause();
+            }
+
+        });
+
+        bouncingBall.setOnMouseReleased(e
+                -> {
+            bouncingBall.play();
+        });
+    
+    // Increase and decrease animation
+
+    bouncingBall.setOnKeyPressed (e  
+        -> {
+    if (e.getCode() == KeyCode.UP) {
+            bouncingBall.increaseSpeed();
+        } else if (e.getCode() == KeyCode.DOWN) {
+            bouncingBall.decreaseSpeed();
+        }
+
+    }
+
+    );
+    }
+    public static void main(String[] args) {
+        launch(args);
+    }
+}
+
+
+ diff --git a/Semester 3/Assignments/lab3_CalebFontenot/PrintedHTMLs/BouncingBall.html b/Semester 3/Assignments/lab3_CalebFontenot/PrintedHTMLs/BouncingBall.html new file mode 100644 index 0000000..423946b --- /dev/null +++ b/Semester 3/Assignments/lab3_CalebFontenot/PrintedHTMLs/BouncingBall.html @@ -0,0 +1,108 @@ + + + +BouncingBall.java + + + + +
/home/caleb/ASDV-Java/Semester 3/Assignments/lab3_CalebFontenot/src/lab3_calebfontenot/BouncingBall.java
+
+/*
+ * 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 lab3_calebfontenot;
+
+import javafx.animation.KeyFrame;
+import javafx.animation.Timeline;
+import static javafx.application.Application.launch;
+import javafx.beans.property.DoubleProperty;
+import javafx.event.ActionEvent;
+import javafx.event.EventHandler;
+import javafx.scene.layout.Pane;
+import javafx.scene.paint.Color;
+import javafx.scene.shape.Circle;
+import javafx.util.Duration;
+
+/**
+ *
+ * @author caleb
+ */
+public class BouncingBall extends Pane {
+
+    final double radius = 20;
+    private double x = radius, y = radius;
+    private double dx = 1, dy = 1;
+    private Circle circle = new Circle(x, y, radius);
+    private Timeline animation;
+
+    public BouncingBall()
+    {
+        circle.setFill(Color.BROWN); // Set ball color
+        getChildren().add(circle); // Place a ball into this pane
+
+        // Create an animation for moving the ball
+        animation = new Timeline(new KeyFrame(Duration.millis(1), new EventHandler<ActionEvent>() {
+            @Override
+            public void handle(ActionEvent t)
+            {
+                moveBall();
+            }
+        })
+        );
+        animation.setRate(animation.getRate() * 20);
+        animation.setCycleCount(Timeline.INDEFINITE);
+        animation.play();
+    }
+    
+private void moveBall() {
+    // Check boundaries
+    if (x < radius || x > getWidth() - radius) {
+        dx *= -1; // Change ball move direction
+    }
+    if (y < radius || y > getHeight() - radius) {
+        dy *= -1; // Change ball move direction
+    }
+    
+    // Adjust ball position by 1 or -1
+    x += dx;
+    y += dy;
+    circle.setCenterX(x);
+    circle.setCenterY(y);
+}
+public void play() {
+    animation.play();
+}
+
+public void pause() {
+    animation.pause();
+}
+
+public void increaseSpeed() {
+    animation.setRate(animation.getRate() * 1.5);
+    System.out.println(animation.getRate());
+}
+
+public void decreaseSpeed() {
+    animation.setRate(animation.getRate() * 1.5 > 0 ? animation.getRate() / 1.5 : 0);
+    System.out.println(animation.getRate());
+}
+
+public DoubleProperty rateProperty() {
+    return animation.rateProperty();
+}
+}
+
+
+ diff --git a/Semester 3/Assignments/lab3_CalebFontenot/nbproject/private/private.xml b/Semester 3/Assignments/lab3_CalebFontenot/nbproject/private/private.xml index d1336bd..6807a2b 100644 --- a/Semester 3/Assignments/lab3_CalebFontenot/nbproject/private/private.xml +++ b/Semester 3/Assignments/lab3_CalebFontenot/nbproject/private/private.xml @@ -2,8 +2,6 @@ - - file:/home/caleb/ASDV-Java/Semester%203/Assignments/lab3_CalebFontenot/src/lab3_calebfontenot/BallControl.java - + diff --git a/Semester 3/ZIPs/MP1_FX_CalebFontenot.zip b/Semester 3/ZIPs/MP1_FX_CalebFontenot.zip new file mode 100644 index 0000000..eada1a3 Binary files /dev/null and b/Semester 3/ZIPs/MP1_FX_CalebFontenot.zip differ diff --git a/Semester 3/ZIPs/lab3_CalebFontenot.zip b/Semester 3/ZIPs/lab3_CalebFontenot.zip new file mode 100644 index 0000000..96fbe82 Binary files /dev/null and b/Semester 3/ZIPs/lab3_CalebFontenot.zip differ diff --git a/Semester 3/ZIPs/lab4_Recursion1_CalebFontenot.zip b/Semester 3/ZIPs/lab4_Recursion1_CalebFontenot.zip new file mode 100644 index 0000000..57d98fa Binary files /dev/null and b/Semester 3/ZIPs/lab4_Recursion1_CalebFontenot.zip differ