diff --git a/MP2_CalebFontenot.zip b/MP2_CalebFontenot.zip new file mode 100644 index 0000000..c2f58d0 Binary files /dev/null and b/MP2_CalebFontenot.zip differ diff --git a/MP2_CalebFontenot/CheckIBSN_10.html b/MP2_CalebFontenot/CheckIBSN_10.html new file mode 100644 index 0000000..fe94df3 --- /dev/null +++ b/MP2_CalebFontenot/CheckIBSN_10.html @@ -0,0 +1,82 @@ + + + +CheckIBSN_10.java + + + + +
/home/caleb/ASDV-Java/MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/CheckIBSN_10.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 com.calebfontenot.mp2_calebfontenot;
+
+import java.util.*;
+
+/**
+ *
+ * @author caleb
+ */
+public class CheckIBSN_10 {
+    public static void main(String[] args)
+    {
+        // Create scanner
+        Scanner input = new Scanner(System.in);
+        // define vars
+        int digit1, digit2, digit3, digit4, digit5, digit6, digit7, digit8, digit9, inputISBN, outputISBN;
+        boolean debug = false;
+        
+        // Scan individual numbers
+        System.out.print("Enter the first 9 digits of an ISBN as an integer: ");
+        inputISBN = input.nextInt(); // Get the first 9 digits of the ISBN
+        
+        
+        // Divide the number up into 9 digits
+        digit1 = inputISBN / 100000000 % 10;
+        digit2 = inputISBN / 10000000 % 10;
+        digit3 = inputISBN / 1000000 % 10;
+        digit4 = inputISBN / 100000 % 10;
+        digit5 = inputISBN / 10000 % 10;
+        digit6 = inputISBN / 1000 % 10;
+        digit7 = inputISBN / 100 % 10;
+        digit8 = inputISBN / 10 % 10;
+        digit9 = inputISBN / 1 % 10;
+        //System.out.println(digit1 +"" + digit2 +"" + digit3 +"" + digit4 +"" + digit5 +"" + digit1 +"" + );
+        //Print digits for debugging
+        if (debug == true)
+        {
+            System.out.println("inputISBN: " + inputISBN);
+            System.out.println("ISBN split into 9 digits: " + (digit1) + " " + (digit2) + " " + (digit3) + " " + (digit4) + " " + (digit5) + " " + (digit6) + " " + (digit7) + " " + (digit8) + " " + (digit9));
+        }
+        // Calculate!
+        outputISBN = ((digit1 * 1) + (digit2 * 2) + (digit3 * 3) + (digit4 * 4) + (digit5 * 5) + (digit6 * 6) + (digit7 * 7) + (digit8 * 8) + (digit9 * 9)) % 11;
+        
+        
+        //Output
+        if (outputISBN == 10)
+        {
+            System.out.println("The ISBN-10 number is " + inputISBN + "X");
+        }
+        else
+        {
+            System.out.println("The ISBN-10 number is " + inputISBN + outputISBN);
+        }
+    }
+}
+
+
+ diff --git a/MP2_CalebFontenot/DayOfTheWeek.html b/MP2_CalebFontenot/DayOfTheWeek.html new file mode 100644 index 0000000..efd0f7f --- /dev/null +++ b/MP2_CalebFontenot/DayOfTheWeek.html @@ -0,0 +1,98 @@ + + + +DayOfTheWeek.java + + + + +
/home/caleb/ASDV-Java/MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/DayOfTheWeek.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 com.calebfontenot.mp2_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class DayOfTheWeek {
+    public static void main(String[] args) {
+        // Create scanner
+        Scanner input = new Scanner(System.in);
+        // Define variables
+        int dayOfTheWeek,
+            dayOfTheMonth,
+            century,
+            yearOfTheCentury,
+            month,
+            year;
+        String weekDay = "nullDay";
+        
+        // Prompt for input
+        System.out.print("Enter year: (e.g., 2022): ");
+        year = input.nextInt();
+        System.out.print("Enter month: 1-12: ");
+        month = input.nextInt();
+        System.out.print("Enter day of the month: 1-31: ");
+        dayOfTheMonth = input.nextInt();
+        
+        
+        // Calculate
+        century = (year / 100); //We are in the 21st century
+        yearOfTheCentury = year % 100;
+        
+        dayOfTheWeek = ((dayOfTheMonth + ((26 * (month + 1)) / 10) + yearOfTheCentury + (yearOfTheCentury / 4) + (century / 4) + (5 * century)) % 7);
+        System.out.println(dayOfTheWeek);
+        
+        // Switch moment
+        switch (dayOfTheWeek) {
+            case 0:
+                weekDay = "Saturday";
+            break;
+            case 1:
+                weekDay = "Sunday";
+            break;
+            case 2:
+                weekDay = "Monday";
+            break;
+            case 3:
+                weekDay = "Tuesday";
+            break;
+            case 4:
+                weekDay = "Wednesday";
+            break;
+            case 5:
+                weekDay = "Thursday";
+            break;
+            case 6:
+                weekDay = "Friday";
+            break;
+        }
+        
+        
+        // Output
+        System.out.println("Day of the week is " + weekDay);
+    }
+}
+
+
+ diff --git a/MP2_CalebFontenot/RandomNumber.html b/MP2_CalebFontenot/RandomNumber.html new file mode 100644 index 0000000..23f5a01 --- /dev/null +++ b/MP2_CalebFontenot/RandomNumber.html @@ -0,0 +1,67 @@ + + + +RandomNumber.java + + + + +
/home/caleb/ASDV-Java/MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/RandomNumber.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 com.calebfontenot.mp2_calebfontenot;
+
+
+/**
+ *
+ * @author caleb
+ */
+public class RandomNumber {
+    public static void main(String[] args)
+    {
+        // Define vars
+        int number = (int) (Math.random() * 12) + 1;
+        System.out.println("Random generated number is " + number);
+        
+        //long if else chain
+        if (number == 1)
+            System.out.println("Month is January");
+        else if (number == 2)
+            System.out.println("Month is February");
+        else if (number == 3)
+            System.out.println("Month is March");
+        else if (number == 4)
+            System.out.println("Month is April");
+        else if (number == 5)
+            System.out.println("Month is June");
+        else if (number == 7)
+            System.out.println("Month is July");
+        else if (number == 8)
+            System.out.println("Month is August");
+        else if (number == 9)
+            System.out.println("Month is September");
+        else if (number == 10)
+            System.out.println("Month is October");
+        else if (number == 11)
+            System.out.println("Month is November");
+        else if (number == 12)
+            System.out.println("Month is December");
+    }
+}
+
+
+ diff --git a/MP2_CalebFontenot/RockPaperScissors.html b/MP2_CalebFontenot/RockPaperScissors.html new file mode 100644 index 0000000..0b58d09 --- /dev/null +++ b/MP2_CalebFontenot/RockPaperScissors.html @@ -0,0 +1,77 @@ + + + +RockPaperScissors.java + + + + +
/home/caleb/ASDV-Java/MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/RockPaperScissors.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 com.calebfontenot.mp2_calebfontenot;
+
+/**
+ *
+ * @author caleb
+ */
+public class RockPaperScissors {
+
+    public static void main(String[] args) {
+        java.util.Scanner input = new java.util.Scanner(System.in);
+        System.out.println("Rock, Paper, Scissors! Pick a number to continue.");
+        while (true) {
+            int computerNumber = (int) (Math.random() * 3);
+            System.out.print("scissors (0), rock (1), paper (2): ");
+            int userNumber = input.nextInt();
+            System.out.println("computer number: " + computerNumber);
+            switch (computerNumber) {
+                case 0:
+                    if (userNumber == 0) {
+                        System.out.print("The computer chose scissors. You also picked scissors. It's a draw!");
+                    } else if (userNumber == 1) {
+                        System.out.print("The computer chose scissors. You picked rock. You won!");
+                    } else if (userNumber == 3) {
+                        System.out.print("The computer chose scissors. You picked paper. You lost.");
+                    }
+                    break;
+                case 1:
+                    if (userNumber == 0) {
+                        System.out.print("The computer chose rock. You chose scissors. You lost.");
+                    } else if (userNumber == 1) {
+                        System.out.print("The computer chose rock. You also picked rock. It's a draw!");
+                    } else if (userNumber == 3) {
+                        System.out.print("The computer chose rock. You picked paper. You won!");
+                    }
+                    break;
+                case 2:
+                    if (userNumber == 0) {
+                        System.out.print("The computer chose paper. You picked scissors. You won!");
+                    } else if (userNumber == 1) {
+                        System.out.print("The computer chose paper. You picked rock. You lost.");
+                    } else if (userNumber == 3) {
+                        System.out.print("The computer chose paper. You also picked paper. It's a draw!");
+                    }
+                    break;
+            }
+            System.out.println("");
+        }
+    }
+}
+
+
+ diff --git a/MP2_CalebFontenot/TrianglePerimeter.html b/MP2_CalebFontenot/TrianglePerimeter.html new file mode 100644 index 0000000..e0b8317 --- /dev/null +++ b/MP2_CalebFontenot/TrianglePerimeter.html @@ -0,0 +1,53 @@ + + + +TrianglePerimeter.java + + + + +
/home/caleb/ASDV-Java/MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/TrianglePerimeter.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 com.calebfontenot.mp2_calebfontenot;
+
+/**
+ *
+ * @author caleb
+ */
+public class TrianglePerimeter {
+    public static void main(String[] args) {
+        java.util.Scanner input = new java.util.Scanner(System.in);
+        
+        // Enter three edges
+        System.out.print("Enter three edges (length in double): ");
+        double edge1 = input.nextDouble(),
+               edge2 = input.nextDouble(),
+               edge3 = input.nextDouble();
+        
+        // Display results
+        boolean isValid = (edge1 + edge2 > edge3) && (edge1 + edge3 > edge2) && (edge2 + edge3 > edge1);
+        
+        // Display results
+        if (isValid)
+            System.out.println("The perimeter is " + (edge1 + edge2 + edge3));
+        else
+            System.out.println("Input is invalid");
+    }
+}
+
+
+ diff --git a/MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/DayOfTheWeek.java b/MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/DayOfTheWeek.java new file mode 100644 index 0000000..78c7402 --- /dev/null +++ b/MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/DayOfTheWeek.java @@ -0,0 +1,71 @@ +/* + * 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 com.calebfontenot.mp2_calebfontenot; + +import java.util.Scanner; + +/** + * + * @author caleb + */ +public class DayOfTheWeek { + public static void main(String[] args) { + // Create scanner + Scanner input = new Scanner(System.in); + // Define variables + int dayOfTheWeek, + dayOfTheMonth, + century, + yearOfTheCentury, + month, + year; + String weekDay = "nullDay"; + + // Prompt for input + System.out.print("Enter year: (e.g., 2022): "); + year = input.nextInt(); + System.out.print("Enter month: 1-12: "); + month = input.nextInt(); + System.out.print("Enter day of the month: 1-31: "); + dayOfTheMonth = input.nextInt(); + + + // Calculate + century = (year / 100); //We are in the 21st century + yearOfTheCentury = year % 100; + + dayOfTheWeek = ((dayOfTheMonth + ((26 * (month + 1)) / 10) + yearOfTheCentury + (yearOfTheCentury / 4) + (century / 4) + (5 * century)) % 7); + System.out.println(dayOfTheWeek); + + // Switch moment + switch (dayOfTheWeek) { + case 0: + weekDay = "Saturday"; + break; + case 1: + weekDay = "Sunday"; + break; + case 2: + weekDay = "Monday"; + break; + case 3: + weekDay = "Tuesday"; + break; + case 4: + weekDay = "Wednesday"; + break; + case 5: + weekDay = "Thursday"; + break; + case 6: + weekDay = "Friday"; + break; + } + + + // Output + System.out.println("Day of the week is " + weekDay); + } +} diff --git a/MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/RockPaperScissors.java b/MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/RockPaperScissors.java new file mode 100644 index 0000000..01fcc49 --- /dev/null +++ b/MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/RockPaperScissors.java @@ -0,0 +1,53 @@ +/* + * 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 com.calebfontenot.mp2_calebfontenot; + +/** + * + * @author caleb + */ +public class RockPaperScissors { + + public static void main(String[] args) { + java.util.Scanner input = new java.util.Scanner(System.in); + System.out.println("Rock, Paper, Scissors! Pick a number to continue."); + while (true) { + int computerNumber = (int) (Math.random() * 3); + System.out.print("scissors (0), rock (1), paper (2): "); + int userNumber = input.nextInt(); + System.out.println("computer number: " + computerNumber); + switch (computerNumber) { + case 0: + if (userNumber == 0) { + System.out.print("The computer chose scissors. You also picked scissors. It's a draw!"); + } else if (userNumber == 1) { + System.out.print("The computer chose scissors. You picked rock. You won!"); + } else if (userNumber == 3) { + System.out.print("The computer chose scissors. You picked paper. You lost."); + } + break; + case 1: + if (userNumber == 0) { + System.out.print("The computer chose rock. You chose scissors. You lost."); + } else if (userNumber == 1) { + System.out.print("The computer chose rock. You also picked rock. It's a draw!"); + } else if (userNumber == 3) { + System.out.print("The computer chose rock. You picked paper. You won!"); + } + break; + case 2: + if (userNumber == 0) { + System.out.print("The computer chose paper. You picked scissors. You won!"); + } else if (userNumber == 1) { + System.out.print("The computer chose paper. You picked rock. You lost."); + } else if (userNumber == 3) { + System.out.print("The computer chose paper. You also picked paper. It's a draw!"); + } + break; + } + System.out.println(""); + } + } +} diff --git a/MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/TrianglePerimeter.java b/MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/TrianglePerimeter.java new file mode 100644 index 0000000..47cb70f --- /dev/null +++ b/MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/TrianglePerimeter.java @@ -0,0 +1,30 @@ +/* + * 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 com.calebfontenot.mp2_calebfontenot; + +/** + * + * @author caleb + */ +public class TrianglePerimeter { + public static void main(String[] args) { + java.util.Scanner input = new java.util.Scanner(System.in); + + // Enter three edges + System.out.print("Enter three edges (length in double): "); + double edge1 = input.nextDouble(), + edge2 = input.nextDouble(), + edge3 = input.nextDouble(); + + // Display results + boolean isValid = (edge1 + edge2 > edge3) && (edge1 + edge3 > edge2) && (edge2 + edge3 > edge1); + + // Display results + if (isValid) + System.out.println("The perimeter is " + (edge1 + edge2 + edge3)); + else + System.out.println("Input is invalid"); + } +} diff --git a/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/IfElse4.java b/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/IfElse4.java index b8e1250..5560c38 100644 --- a/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/IfElse4.java +++ b/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/IfElse4.java @@ -55,7 +55,7 @@ public class IfElse4 { double grade; String letterGrade; - while (true) { + while (true) { // Unintended behavior: This will only run twice. I intended this try and catch to run indefinately, but it only will catch once before terminating on its own. // Call ifLogic function try { // Prompt for input