diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/nbproject/project.properties b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/nbproject/project.properties index dbc5a47..41139c7 100644 --- a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/nbproject/project.properties +++ b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/nbproject/project.properties @@ -107,7 +107,7 @@ manifest.custom.permissions= manifest.file=manifest.mf meta.inf.dir=${src.dir}/META-INF mkdist.disabled=false -platform.active=JDK_8__System_ +platform.active=JDK_1.8 run.classpath=\ ${dist.jar}:\ ${javac.classpath}:\ diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0000.wav b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0000.wav new file mode 100644 index 0000000..d888223 Binary files /dev/null and b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0000.wav differ diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0001.wav b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0001.wav new file mode 100644 index 0000000..c718aae Binary files /dev/null and b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0001.wav differ diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0002.wav b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0002.wav new file mode 100644 index 0000000..5f9e55e Binary files /dev/null and b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0002.wav differ diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0003.wav b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0003.wav new file mode 100644 index 0000000..a9f6ffe Binary files /dev/null and b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0003.wav differ diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0004.wav b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0004.wav new file mode 100644 index 0000000..e51b0bb Binary files /dev/null and b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0004.wav differ diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0009.wav b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0009.wav new file mode 100644 index 0000000..2ad13cd Binary files /dev/null and b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0009.wav differ diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0010.wav b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0010.wav new file mode 100644 index 0000000..0c66f12 Binary files /dev/null and b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0010.wav differ diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0012.wav b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0012.wav new file mode 100644 index 0000000..9b68ba4 Binary files /dev/null and b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0012.wav differ diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0014.wav b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0014.wav new file mode 100644 index 0000000..3c7226d Binary files /dev/null and b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0014.wav differ diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0016.wav b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0016.wav new file mode 100644 index 0000000..22742d6 Binary files /dev/null and b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0016.wav differ diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0017.wav b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0017.wav new file mode 100644 index 0000000..6251b90 Binary files /dev/null and b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0017.wav differ diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0018.wav b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0018.wav new file mode 100644 index 0000000..5388a13 Binary files /dev/null and b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0018.wav differ diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0019.wav b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0019.wav new file mode 100644 index 0000000..85fb935 Binary files /dev/null and b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0019.wav differ diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0020.wav b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0020.wav new file mode 100644 index 0000000..c3ec3c2 Binary files /dev/null and b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0020.wav differ diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0021.wav b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0021.wav new file mode 100644 index 0000000..0803b10 Binary files /dev/null and b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0021.wav differ diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0022.wav b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0022.wav new file mode 100644 index 0000000..fb69172 Binary files /dev/null and b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0022.wav differ diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0023.wav b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0023.wav new file mode 100644 index 0000000..a2b2d6a Binary files /dev/null and b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0023.wav differ diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0024.wav b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0024.wav new file mode 100644 index 0000000..9e7c30f Binary files /dev/null and b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0024.wav differ diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0025.wav b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0025.wav new file mode 100644 index 0000000..6cfb8e4 Binary files /dev/null and b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0025.wav differ diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0026.wav b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0026.wav new file mode 100644 index 0000000..4968470 Binary files /dev/null and b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0026.wav differ diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0027.wav b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0027.wav new file mode 100644 index 0000000..294843f Binary files /dev/null and b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0027.wav differ diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0028.wav b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0028.wav new file mode 100644 index 0000000..702d016 Binary files /dev/null and b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0028.wav differ diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0029.wav b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0029.wav new file mode 100644 index 0000000..cddc2f7 Binary files /dev/null and b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0029.wav differ diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0030.wav b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0030.wav new file mode 100644 index 0000000..58dc8a4 Binary files /dev/null and b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0030.wav differ diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0031.wav b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0031.wav new file mode 100644 index 0000000..89ee426 Binary files /dev/null and b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0031.wav differ diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0032.wav b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0032.wav new file mode 100644 index 0000000..ed8586d Binary files /dev/null and b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0032.wav differ diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/src/MP2_chapter4_CalebFontenot/BallControl.java b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/src/MP2_chapter4_CalebFontenot/BallControl.java index 24cfe5a..137fa0b 100644 --- a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/src/MP2_chapter4_CalebFontenot/BallControl.java +++ b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/src/MP2_chapter4_CalebFontenot/BallControl.java @@ -17,8 +17,12 @@ import javafx.stage.Stage; */ public class BallControl extends Application { + private boolean mouseFocus = false; + private int racketPosition = 0; + @Override - public void start(Stage primaryStage) throws Exception { + public void start(Stage primaryStage) throws Exception + { BouncingBall bouncingBall = new BouncingBall(); // Create a scene and place it in the stage @@ -27,19 +31,22 @@ public class BallControl extends Application { primaryStage.setScene(scene); primaryStage.show(); bouncingBall.requestFocus(); + bouncingBall.showInfoLabel(); + bouncingBall.setOnMouseEntered(e -> { + mouseFocus = true; bouncingBall.hideInfoLabel(); bouncingBall.play(); }); bouncingBall.setOnMouseExited(e -> { - bouncingBall.showInfoLabel(); - bouncingBall.pause(); + mouseFocus = false; }); bouncingBall.setOnMouseMoved(new EventHandler() { @Override - public void handle(MouseEvent event) { + public void handle(MouseEvent event) + { double mouseX = event.getSceneX() - (bouncingBall.RACKET_LENGTH / 2); // set relative to center of racket bouncingBall.moveRacket(mouseX); } @@ -49,6 +56,20 @@ public class BallControl extends Application { // Increase and decrease animation bouncingBall.setOnKeyPressed(e -> { + if (e.getCode() == KeyCode.LEFT && mouseFocus == false) { + bouncingBall.hideInfoLabel(); + if (racketPosition > 0) { + racketPosition = racketPosition - 30; + } + bouncingBall.moveRacket(racketPosition); + } + if (e.getCode() == KeyCode.RIGHT && mouseFocus == false) { + bouncingBall.hideInfoLabel(); + if (racketPosition < bouncingBall.getWidth()) { + racketPosition = racketPosition + 30; + } + bouncingBall.moveRacket(racketPosition); + } if (e.getCode() == KeyCode.UP) { bouncingBall.increaseSpeed(); } else if (e.getCode() == KeyCode.DOWN) { @@ -59,7 +80,8 @@ public class BallControl extends Application { ); } - public static void main(String[] args) { + public static void main(String[] args) + { launch(args); } } diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/src/MP2_chapter4_CalebFontenot/BouncingBall.java b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/src/MP2_chapter4_CalebFontenot/BouncingBall.java index b9c125f..b5957c5 100644 --- a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/src/MP2_chapter4_CalebFontenot/BouncingBall.java +++ b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/src/MP2_chapter4_CalebFontenot/BouncingBall.java @@ -28,6 +28,7 @@ import javafx.util.Duration; public class BouncingBall extends Pane { GridPane textPane = new GridPane(); + private final int COLLISION_COOLDOWN = 20; private long timeSinceLastCollisionEvent = 0; final double RACKET_LENGTH = 100; final double radius = 20; @@ -41,33 +42,43 @@ public class BouncingBall extends Pane { private Label playerScoreLabel = new Label("Player Score: 0"); private Label computerScoreLabel = new Label("Computer Score: 0"); - - private Timeline animation; private int computerScore, playerScore = 0; - public BouncingBall() { + public BouncingBall() + { circle.setFill(Color.RED); // Set ball color racket.setFill(Color.BLUE); textPane.add(racketTime, 0, 0); textPane.add(ballCords, 0, 1); textPane.add(playerScoreLabel, 0, 2); textPane.add(computerScoreLabel, 0, 3); - getChildren().addAll(circle, racket, textPane, infoLabel); // Place a ball into this pane + getChildren().addAll(circle, racket, textPane); // Place a ball into this pane racket.relocate(0, 580); - infoLabel.relocate(getHeight() / 4.0, getWidth() / 2.0); // Create an animation for moving the ball animation = new Timeline(new KeyFrame(Duration.millis(1), new EventHandler() { @Override - public void handle(ActionEvent t) { + public void handle(ActionEvent t) + { + timeSinceLastCollisionEvent++; racketTime.setText("Frames since last collision: " + timeSinceLastCollisionEvent); moveBall(); - if (y >= (getHeight() - 20) && (timeSinceLastCollisionEvent > 500)) { + // Process collisions + if (y >= (getHeight() - 20) && (timeSinceLastCollisionEvent > COLLISION_COOLDOWN)) { timeSinceLastCollisionEvent = 0; + playSound("collision"); incrementComputerScore(); } + if ((x <= 20 && (timeSinceLastCollisionEvent > COLLISION_COOLDOWN)) || ((x >= getWidth() - 20) && (timeSinceLastCollisionEvent > COLLISION_COOLDOWN))) { + timeSinceLastCollisionEvent = 0; + playSound("collision"); + } + if (y <= 20 && (timeSinceLastCollisionEvent > COLLISION_COOLDOWN)) { + timeSinceLastCollisionEvent = 0; + playSound("collision"); + } } }) ); @@ -76,20 +87,23 @@ public class BouncingBall extends Pane { } - private boolean processRacketCollision() { + private boolean processRacketCollision() + { boolean racketCollision = racket.getBoundsInParent().intersects(circle.getBoundsInParent()); - if (racketCollision && (timeSinceLastCollisionEvent > 500)) { // This is second condition is a cooldown. It prevents odd behavior happening with the ball and the racket if the racket hits the ball at certain angles. + if (racketCollision && (timeSinceLastCollisionEvent > COLLISION_COOLDOWN)) { // This is second condition is a cooldown. It prevents odd behavior happening with the ball and the racket if the racket hits the ball at certain angles. System.out.println("Racket collision detected!"); timeSinceLastCollisionEvent = 0; incrementPlayerScore(); + playSound("racket"); return true; } else { return false; } } - private void moveBall() { + private void moveBall() + { // Check boundaries if (x < radius || x > getWidth() - radius) { @@ -107,33 +121,40 @@ public class BouncingBall extends Pane { ballCoordsToLabel(); } - public void play() { + public void play() + { animation.play(); } - public void pause() { + public void pause() + { animation.pause(); } - public void increaseSpeed() { + public void increaseSpeed() + { animation.setRate(animation.getRate() * 1.5); System.out.println(animation.getRate()); } - public void decreaseSpeed() { + public void decreaseSpeed() + { animation.setRate(animation.getRate() * 1.5 > 0 ? animation.getRate() / 1.5 : 0); System.out.println(animation.getRate()); } - public DoubleProperty rateProperty() { + public DoubleProperty rateProperty() + { return animation.rateProperty(); } - public void moveRacket(double x) { + public void moveRacket(double x) + { racket.relocate(x, 580); } - public void showInfoLabel() { + public void showInfoLabel() + { double paneHeight = getHeight(); double paneWidth = getWidth(); getChildren().add(infoLabel); @@ -141,34 +162,58 @@ public class BouncingBall extends Pane { infoLabel.relocate(paneWidth / 4.0, paneHeight / 2.0); } - public void hideInfoLabel() { + public void hideInfoLabel() + { getChildren().remove(infoLabel); } - private void incrementPlayerScore() { + private void incrementPlayerScore() + { playerScoreLabel.setText("Player score: " + ++playerScore); - playSound(); } - private void incrementComputerScore() { + private void incrementComputerScore() + { computerScoreLabel.setText("Computer score: " + ++computerScore); - //playSound(); + } - private void ballCoordsToLabel() { + private void ballCoordsToLabel() + { ballCords.setText("Ball coords: " + x + ", " + y); } - private void playSound() { + + private void playSound(String sampleType) + { + String sample = ""; int randInt = (int) (Math.random() * 2); - String sample; - if (randInt == 0) { - sample = "5"; - } else { - sample = "7"; + switch (sampleType) { + case "collision": + switch (randInt) { + case 0: + sample = "05"; + break; + case 1: + sample = "07"; + break; + } + break; + case "racket": + switch (randInt) { + case 0: + sample = "10"; + break; + case 1: + sample = "12"; + break; + } } - Media sound = new Media(new File("sound/Sample_000"+sample+".wav").toURI().toString()); + + Media sound = new Media(new File("sound/Sample_00" + sample + ".wav").toURI().toString()); MediaPlayer mediaPlayer = new MediaPlayer(sound); + mediaPlayer.setStartTime(Duration.ZERO); + mediaPlayer.play(); //mediaPlayer.setOnEndOfMedia(); } diff --git a/Semester 3/Assignments/lab5-recursion2_CalebFontenot/Printed HTMLs/NestedLoopsIndexes.html b/Semester 3/Assignments/lab5-recursion2_CalebFontenot/Printed HTMLs/NestedLoopsIndexes.html new file mode 100644 index 0000000..a455e63 --- /dev/null +++ b/Semester 3/Assignments/lab5-recursion2_CalebFontenot/Printed HTMLs/NestedLoopsIndexes.html @@ -0,0 +1,61 @@ + + + +NestedLoopsIndexes.java + + + + +
/home/caleb/ASDV-Java/Semester 3/Assignments/lab5-recursion2_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/lab5/recursion2_calebfontenot/NestedLoopsIndexes.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 edu.slcc.asdv.caleb.lab5.recursion2_calebfontenot;
+
+/**
+ *
+ * @author caleb
+ */
+public class NestedLoopsIndexes {
+   static final int ROWS = 3;
+   static final int COLUMNS = 5;
+    
+    public static void nestedLoopsIndexesR(int i, int j) {
+        if (j == COLUMNS) {
+            System.out.println();
+            return;
+        } else if (i == ROWS) {
+            return;
+        }
+        System.out.print(i + ", " + j + "    ");
+        nestedLoopsIndexesR(i, ++j);
+        if (i + 1 == j) {
+            nestedLoopsIndexesR(++i, 0);
+        }
+    }
+    public static void main(String[] args)
+    {
+        nestedLoopsIndexesR(0, 0);
+    }
+}
+
+
+ diff --git a/Semester 3/Assignments/lab5-recursion2_CalebFontenot/Printed HTMLs/OccurancesOfChar.html b/Semester 3/Assignments/lab5-recursion2_CalebFontenot/Printed HTMLs/OccurancesOfChar.html new file mode 100644 index 0000000..9941b3a --- /dev/null +++ b/Semester 3/Assignments/lab5-recursion2_CalebFontenot/Printed HTMLs/OccurancesOfChar.html @@ -0,0 +1,58 @@ + + + +OccurancesOfChar.java + + + + +
/home/caleb/ASDV-Java/Semester 3/Assignments/lab5-recursion2_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/lab5/recursion2_calebfontenot/OccurancesOfChar.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 edu.slcc.asdv.caleb.lab5.recursion2_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class OccurancesOfChar {
+    public static void main(String[] args)
+    {
+        Scanner input = new Scanner(System.in);
+        System.out.print("Enter a string: ");
+        String s = input.nextLine();
+        System.out.print("Enter a character: ");
+        char ch =input.nextLine().charAt(0);
+        int times = count(s, ch);
+        System.out.println(ch + " appears " + times
+        + (times > 1 ? " times " : " time ") + "in " + s);
+    }
+    public static int count(String str, char a) {
+        int result = 0;
+        if (str.length() > 0) {
+            result = count(str.substring(1), a) +
+                    (( str.charAt(0) == a) ? 1 : 0);
+        }
+        return result;
+    }
+}
+
+
+ diff --git a/Semester 3/Assignments/lab5-recursion2_CalebFontenot/Printed HTMLs/OccurencesOfSpecifiedCharacterInArray.html b/Semester 3/Assignments/lab5-recursion2_CalebFontenot/Printed HTMLs/OccurencesOfSpecifiedCharacterInArray.html new file mode 100644 index 0000000..71eb1ce --- /dev/null +++ b/Semester 3/Assignments/lab5-recursion2_CalebFontenot/Printed HTMLs/OccurencesOfSpecifiedCharacterInArray.html @@ -0,0 +1,61 @@ + + + +OccurencesOfSpecifiedCharacterInArray.java + + + + +
/home/caleb/ASDV-Java/Semester 3/Assignments/lab5-recursion2_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/lab5/recursion2_calebfontenot/OccurencesOfSpecifiedCharacterInArray.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 edu.slcc.asdv.caleb.lab5.recursion2_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class OccurencesOfSpecifiedCharacterInArray {
+    public static void main(String[] args)
+    {
+        System.out.print("Enter a string: ");
+        Scanner input = new Scanner(System.in);
+        String s = input.nextLine();
+        char[] items = s.toCharArray();
+        
+        System.out.print("Enter a character: ");
+        char ch = input.nextLine().trim().charAt(0);
+        
+        System.out.println(ch + "  appears " + count(items, ch) + " times.");
+    }
+    public static int count(char[] chars, char ch) {
+        return count(chars, chars.length - 1, ch);
+    }
+    public static int count(char[] chars, int high, char ch) {
+        if (high >= 0) {
+            return count(chars, high - 1, ch) + (ch == chars[high] ? 1 : 0);
+        } else {
+            return 0;
+        }
+    }
+}
+
+
+ diff --git a/Semester 3/Assignments/lab5-recursion2_CalebFontenot/Printed HTMLs/ReverseInt.html b/Semester 3/Assignments/lab5-recursion2_CalebFontenot/Printed HTMLs/ReverseInt.html new file mode 100644 index 0000000..ccfda2e --- /dev/null +++ b/Semester 3/Assignments/lab5-recursion2_CalebFontenot/Printed HTMLs/ReverseInt.html @@ -0,0 +1,55 @@ + + + +ReverseInt.java + + + + +
/home/caleb/ASDV-Java/Semester 3/Assignments/lab5-recursion2_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/lab5/recursion2_calebfontenot/ReverseInt.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 edu.slcc.asdv.caleb.lab5.recursion2_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class ReverseInt {
+    public static void main(String[] args)
+    {
+        Scanner input = new Scanner(System.in);
+        System.out.print("Enter an integer: ");
+        int i = input.nextInt();
+        System.out.print("The reversal of " + i + " is ");
+        reverseDisplay(i);
+        System.out.println();
+    }
+    public static void reverseDisplay(int value) {
+        if (value != 0) {
+            System.out.print(value % 10);
+            value = value / 10;
+            reverseDisplay(value);
+        }
+    }
+}
+
+
+ diff --git a/Semester 3/Assignments/lab5-recursion2_CalebFontenot/Printed HTMLs/SelectionSortR.html b/Semester 3/Assignments/lab5-recursion2_CalebFontenot/Printed HTMLs/SelectionSortR.html new file mode 100644 index 0000000..fc3c4e6 --- /dev/null +++ b/Semester 3/Assignments/lab5-recursion2_CalebFontenot/Printed HTMLs/SelectionSortR.html @@ -0,0 +1,82 @@ + + + +SelectionSortR.java + + + + +
/home/caleb/ASDV-Java/Semester 3/Assignments/lab5-recursion2_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/lab5/recursion2_calebfontenot/SelectionSortR.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 edu.slcc.asdv.caleb.lab5.recursion2_calebfontenot;
+
+/**
+ *
+ * @author caleb
+ */
+public class SelectionSortR {
+
+    public static void selectionSortR(int[] arr)
+    {
+        selectionSortR(arr, 0, arr.length);
+    }
+
+    public static void swap(int[] arr, int i, int j)
+    {
+        int temp = arr[i];
+        arr[i] = arr[j];
+        arr[j] = temp;
+    }
+
+    public static void selectionSortR(int[] arr, int i, int n)
+    {
+        // Selection sort
+        int min = i;
+        for (int j = i + 1; j < n; ++j) {
+            if (arr[j] < arr[min]) {
+                min = j;
+            }
+        }
+        swap(arr, min, i);
+        if ( i + 1 < n) {
+            selectionSortR(arr, i +1, n);
+        }
+    }
+
+    public static void main(String[] args)
+    {
+        int[] arr = {
+            8, 2, 1, 1, 7, 4, -1, 50, 49
+        };
+        selectionSortR(arr);
+
+        for (int i = 0; i < arr.length; ++i) {
+            System.out.print(arr[i] + " ");
+        }
+        System.out.println();
+    }
+}
+
+
+ diff --git a/Semester 3/Assignments/lab5-recursion2_CalebFontenot/Printed HTMLs/SumOfDigits.html b/Semester 3/Assignments/lab5-recursion2_CalebFontenot/Printed HTMLs/SumOfDigits.html new file mode 100644 index 0000000..0fd20df --- /dev/null +++ b/Semester 3/Assignments/lab5-recursion2_CalebFontenot/Printed HTMLs/SumOfDigits.html @@ -0,0 +1,62 @@ + + + +SumOfDigits.java + + + + +
/home/caleb/ASDV-Java/Semester 3/Assignments/lab5-recursion2_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/lab5/recursion2_calebfontenot/SumOfDigits.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 edu.slcc.asdv.caleb.lab5.recursion2_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class SumOfDigits {
+
+    public static void main(String[] args)
+    {
+        Scanner input = new Scanner(System.in);
+        System.out.print("Enter an integer: ");
+        int i = input.nextInt();
+        System.out.print("The sum of digits in " + i
+                + " is " + sumDigits(i));
+        System.out.println();
+    }
+
+    public static long sumDigits(long n)
+    {
+        // Base case: if the number is a single digit, return it
+        if (n < 10) {
+            return n;
+        } else {
+            // Recursive case: sum the last digit and call the function on the remaining digits
+            long lastDigit = n % 10;
+            long remainingDigits = n / 10;
+            return lastDigit + sumDigits(remainingDigits);
+        }
+    }
+}
+
+
+ diff --git a/Semester 3/Assignments/lab5-recursion2_CalebFontenot/Printed HTMLs/SumSeries1.html b/Semester 3/Assignments/lab5-recursion2_CalebFontenot/Printed HTMLs/SumSeries1.html new file mode 100644 index 0000000..20d9caa --- /dev/null +++ b/Semester 3/Assignments/lab5-recursion2_CalebFontenot/Printed HTMLs/SumSeries1.html @@ -0,0 +1,51 @@ + + + +SumSeries1.java + + + + +
/home/caleb/ASDV-Java/Semester 3/Assignments/lab5-recursion2_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/lab5/recursion2_calebfontenot/SumSeries1.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 edu.slcc.asdv.caleb.lab5.recursion2_calebfontenot;
+
+/**
+ *
+ * @author caleb
+ */
+public class SumSeries1 {
+    public static void main(String[] args)
+    {
+        System.out.printf("%-10s%15s\n", "1", "m(i)");
+        for (int i = 1; i <= 10; ++i) {
+            System.out.printf("%-10d%-15.6f\n",i, m(i));
+        }
+    }
+    public static double m(int i) {
+        if (i == 1) {
+            return 1;
+        } else {
+            return m(i - 1) + 1.0 / i;
+        }
+    }
+}
+
+
+ diff --git a/Semester 3/Assignments/lab5-recursion2_CalebFontenot/Printed HTMLs/SumSeries2.html b/Semester 3/Assignments/lab5-recursion2_CalebFontenot/Printed HTMLs/SumSeries2.html new file mode 100644 index 0000000..181d7af --- /dev/null +++ b/Semester 3/Assignments/lab5-recursion2_CalebFontenot/Printed HTMLs/SumSeries2.html @@ -0,0 +1,51 @@ + + + +SumSeries2.java + + + + +
/home/caleb/ASDV-Java/Semester 3/Assignments/lab5-recursion2_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/lab5/recursion2_calebfontenot/SumSeries2.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 edu.slcc.asdv.caleb.lab5.recursion2_calebfontenot;
+
+/**
+ *
+ * @author caleb
+ */
+public class SumSeries2 {
+    public static void main(String[] args)
+    {
+                System.out.printf("%-10s%15s\n", "i", "m(i)");
+        for (int i = 1; i <= 10; ++i) {
+            System.out.printf("%-10d%-15.6f\n",i, m(i));
+        }
+    }
+    public static double m(int i) {
+        if (i == 1) {
+            return 1.0 / 3;
+        } else {
+            return m(i - 1) + (double) i / (2 * i + 1);
+        }
+    }
+}
+
+
+ diff --git a/Semester 3/Assignments/lab5-recursion2_CalebFontenot/Printed HTMLs/UpperCaseInArray.html b/Semester 3/Assignments/lab5-recursion2_CalebFontenot/Printed HTMLs/UpperCaseInArray.html new file mode 100644 index 0000000..c35910f --- /dev/null +++ b/Semester 3/Assignments/lab5-recursion2_CalebFontenot/Printed HTMLs/UpperCaseInArray.html @@ -0,0 +1,59 @@ + + + +UpperCaseInArray.java + + + + +
/home/caleb/ASDV-Java/Semester 3/Assignments/lab5-recursion2_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/lab5/recursion2_calebfontenot/UpperCaseInArray.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 edu.slcc.asdv.caleb.lab5.recursion2_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class UpperCaseInArray {
+    public static void main(String[] args)
+    {
+        System.out.print("Enter a string: ");
+        Scanner input = new Scanner(System.in);
+        String s = input.nextLine();
+        char[] items = s.toCharArray();
+        System.out.println("The number of uppercase letters is "
+                    + count(items));
+    }
+    
+    public static int count(char[] chars) {
+        return count(chars, chars.length - 1);
+    }
+    public static int count(char[] chars, int high) {
+        if (high >= 0) {
+            return count(chars, high - 1) + (Character.isUpperCase(chars[high]) ? 1 : 0);
+        } else {
+            return 0;
+        }
+    }
+}
+
+
+ diff --git a/Semester 3/Assignments/lab5-recursion2_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/lab5/recursion2_calebfontenot/NestedLoopsIndexes.java b/Semester 3/Assignments/lab5-recursion2_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/lab5/recursion2_calebfontenot/NestedLoopsIndexes.java new file mode 100644 index 0000000..a7e6846 --- /dev/null +++ b/Semester 3/Assignments/lab5-recursion2_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/lab5/recursion2_calebfontenot/NestedLoopsIndexes.java @@ -0,0 +1,32 @@ +/* + * 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 edu.slcc.asdv.caleb.lab5.recursion2_calebfontenot; + +/** + * + * @author caleb + */ +public class NestedLoopsIndexes { + static final int ROWS = 3; + static final int COLUMNS = 5; + + public static void nestedLoopsIndexesR(int i, int j) { + if (j == COLUMNS) { + System.out.println(); + return; + } else if (i == ROWS) { + return; + } + System.out.print(i + ", " + j + " "); + nestedLoopsIndexesR(i, ++j); + if (i + 1 == j) { + nestedLoopsIndexesR(++i, 0); + } + } + public static void main(String[] args) + { + nestedLoopsIndexesR(0, 0); + } +} diff --git a/Semester 3/Assignments/lab5-recursion2_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/lab5/recursion2_calebfontenot/OccurencesOfSpecifiedCharacterInArray.java b/Semester 3/Assignments/lab5-recursion2_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/lab5/recursion2_calebfontenot/OccurencesOfSpecifiedCharacterInArray.java new file mode 100644 index 0000000..77b1f87 --- /dev/null +++ b/Semester 3/Assignments/lab5-recursion2_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/lab5/recursion2_calebfontenot/OccurencesOfSpecifiedCharacterInArray.java @@ -0,0 +1,36 @@ +/* + * 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 edu.slcc.asdv.caleb.lab5.recursion2_calebfontenot; + +import java.util.Scanner; + +/** + * + * @author caleb + */ +public class OccurencesOfSpecifiedCharacterInArray { + public static void main(String[] args) + { + System.out.print("Enter a string: "); + Scanner input = new Scanner(System.in); + String s = input.nextLine(); + char[] items = s.toCharArray(); + + System.out.print("Enter a character: "); + char ch = input.nextLine().trim().charAt(0); + + System.out.println(ch + " appears " + count(items, ch) + " times."); + } + public static int count(char[] chars, char ch) { + return count(chars, chars.length - 1, ch); + } + public static int count(char[] chars, int high, char ch) { + if (high >= 0) { + return count(chars, high - 1, ch) + (ch == chars[high] ? 1 : 0); + } else { + return 0; + } + } +} diff --git a/Semester 3/Assignments/lab5-recursion2_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/lab5/recursion2_calebfontenot/SelectionSortR.java b/Semester 3/Assignments/lab5-recursion2_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/lab5/recursion2_calebfontenot/SelectionSortR.java new file mode 100644 index 0000000..326b3af --- /dev/null +++ b/Semester 3/Assignments/lab5-recursion2_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/lab5/recursion2_calebfontenot/SelectionSortR.java @@ -0,0 +1,52 @@ +/* + * 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 edu.slcc.asdv.caleb.lab5.recursion2_calebfontenot; + +/** + * + * @author caleb + */ +public class SelectionSortR { + + public static void selectionSortR(int[] arr) + { + selectionSortR(arr, 0, arr.length); + } + + public static void swap(int[] arr, int i, int j) + { + int temp = arr[i]; + arr[i] = arr[j]; + arr[j] = temp; + } + + public static void selectionSortR(int[] arr, int i, int n) + { + // Selection sort + int min = i; + for (int j = i + 1; j < n; ++j) { + if (arr[j] < arr[min]) { + min = j; + } + } + swap(arr, min, i); + if ( i + 1 < n) { + selectionSortR(arr, i +1, n); + } + } + + public static void main(String[] args) + { + int[] arr = { + 8, 2, 1, 1, 7, 4, -1, 50, 49 + }; + selectionSortR(arr); + + for (int i = 0; i < arr.length; ++i) { + System.out.print(arr[i] + " "); + } + System.out.println(); + } +} diff --git a/Semester 3/Assignments/lab5-recursion2_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/lab5/recursion2_calebfontenot/SumOfDigits.java b/Semester 3/Assignments/lab5-recursion2_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/lab5/recursion2_calebfontenot/SumOfDigits.java new file mode 100644 index 0000000..75ca503 --- /dev/null +++ b/Semester 3/Assignments/lab5-recursion2_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/lab5/recursion2_calebfontenot/SumOfDigits.java @@ -0,0 +1,37 @@ +/* + * 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 edu.slcc.asdv.caleb.lab5.recursion2_calebfontenot; + +import java.util.Scanner; + +/** + * + * @author caleb + */ +public class SumOfDigits { + + public static void main(String[] args) + { + Scanner input = new Scanner(System.in); + System.out.print("Enter an integer: "); + int i = input.nextInt(); + System.out.print("The sum of digits in " + i + + " is " + sumDigits(i)); + System.out.println(); + } + + public static long sumDigits(long n) + { + // Base case: if the number is a single digit, return it + if (n < 10) { + return n; + } else { + // Recursive case: sum the last digit and call the function on the remaining digits + long lastDigit = n % 10; + long remainingDigits = n / 10; + return lastDigit + sumDigits(remainingDigits); + } + } +} diff --git a/Semester 3/Assignments/lab5-recursion2_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/lab5/recursion2_calebfontenot/UpperCaseInArray.java b/Semester 3/Assignments/lab5-recursion2_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/lab5/recursion2_calebfontenot/UpperCaseInArray.java new file mode 100644 index 0000000..26d9b1b --- /dev/null +++ b/Semester 3/Assignments/lab5-recursion2_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/lab5/recursion2_calebfontenot/UpperCaseInArray.java @@ -0,0 +1,34 @@ +/* + * 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 edu.slcc.asdv.caleb.lab5.recursion2_calebfontenot; + +import java.util.Scanner; + +/** + * + * @author caleb + */ +public class UpperCaseInArray { + public static void main(String[] args) + { + System.out.print("Enter a string: "); + Scanner input = new Scanner(System.in); + String s = input.nextLine(); + char[] items = s.toCharArray(); + System.out.println("The number of uppercase letters is " + + count(items)); + } + + public static int count(char[] chars) { + return count(chars, chars.length - 1); + } + public static int count(char[] chars, int high) { + if (high >= 0) { + return count(chars, high - 1) + (Character.isUpperCase(chars[high]) ? 1 : 0); + } else { + return 0; + } + } +} diff --git a/Semester 3/ZIPs/lab5-recursion2_CalebFontenot.zip b/Semester 3/ZIPs/lab5-recursion2_CalebFontenot.zip new file mode 100644 index 0000000..56af4c7 Binary files /dev/null and b/Semester 3/ZIPs/lab5-recursion2_CalebFontenot.zip differ