diff --git a/.gitignore b/.gitignore index 7a04d75..df7c619 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ /03_Sep13_2022/target/ /lab7_CalebFontenot/target/ /MP2_CalebFontenot/target/ +/lab8_CalebFontenot/target/ diff --git a/lab8_CalebFontenot.zip b/lab8_CalebFontenot.zip new file mode 100644 index 0000000..fbd6b38 Binary files /dev/null and b/lab8_CalebFontenot.zip differ diff --git a/lab8_CalebFontenot/ConditionalOperator1.html b/lab8_CalebFontenot/ConditionalOperator1.html new file mode 100644 index 0000000..34efdb1 --- /dev/null +++ b/lab8_CalebFontenot/ConditionalOperator1.html @@ -0,0 +1,53 @@ + + + +ConditionalOperator1.java + + + + +
/home/caleb/ASDV-Java/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/ConditionalOperator1.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.lab8_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class ConditionalOperator1 {
+    public static void main(String[] args) {
+        Scanner scan = new Scanner(System.in);
+        
+        System.out.print("please enter an even number: ");
+        int number = scan.nextInt();
+        if ( number % 2 == 0 )
+            System.out.print("\n" + number + " fufills the request!");
+        else
+            System.out.print("\n" + number + " does not fufill the request!");
+        
+        System.out.println(number % 2 == 0 ? " yes sir!" : " no sir!");
+    }
+}
+
+
+ diff --git a/lab8_CalebFontenot/ConditionalOperator2.html b/lab8_CalebFontenot/ConditionalOperator2.html new file mode 100644 index 0000000..f60f6ed --- /dev/null +++ b/lab8_CalebFontenot/ConditionalOperator2.html @@ -0,0 +1,45 @@ + + + +ConditionalOperator2.java + + + + +
/home/caleb/ASDV-Java/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/ConditionalOperator2.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.lab8_calebfontenot;
+
+/**
+ *
+ * @author caleb
+ */
+public class ConditionalOperator2 {
+    public static void main(String[] args) {
+        java.util.Scanner input = new java.util.Scanner(System.in);
+        double x = input.nextDouble();
+        double y = input.nextDouble();
+        double z = input.nextDouble();
+        System.out.println((x < y && y < z) ? "sorted" : "not sorted");
+    }
+}
+
+
+ diff --git a/lab8_CalebFontenot/ConditionalOperator3.html b/lab8_CalebFontenot/ConditionalOperator3.html new file mode 100644 index 0000000..ccdd3f9 --- /dev/null +++ b/lab8_CalebFontenot/ConditionalOperator3.html @@ -0,0 +1,45 @@ + + + +ConditionalOperator3.java + + + + +
/home/caleb/ASDV-Java/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/ConditionalOperator3.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.lab8_calebfontenot;
+
+/**
+ *
+ * @author caleb
+ */
+public class ConditionalOperator3 {
+    public static void main(String[] args) {
+        java.util.Scanner input = new java.util.Scanner(System.in);
+        double x = input.nextDouble();
+        double y = input.nextDouble();
+        double z = input.nextDouble();
+        System.out.println((x < y && y < z) ? 100 : 200);
+    }
+}
+
+
+ diff --git a/lab8_CalebFontenot/ConditionalOperator4.html b/lab8_CalebFontenot/ConditionalOperator4.html new file mode 100644 index 0000000..85518a9 --- /dev/null +++ b/lab8_CalebFontenot/ConditionalOperator4.html @@ -0,0 +1,53 @@ + + + +ConditionalOperator4.java + + + + +
/home/caleb/ASDV-Java/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/ConditionalOperator4.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.lab8_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class ConditionalOperator4 {
+    public static void main(String[] args) {
+        Scanner scan = new Scanner(System.in);
+        
+        System.out.print("please enter an even number: ");
+        int number = scan.nextInt();
+        System.out.print("\n" + number + ( number % 2 == 0 ? " fufills the request!" : " does not fufill the request!"));
+
+        if (number % 2 == 0)
+            System.out.println(" yes sir!");
+        else
+            System.out.println(" no sir!");
+    }
+}
+
+
+ diff --git a/lab8_CalebFontenot/DecimalToHex1.html b/lab8_CalebFontenot/DecimalToHex1.html new file mode 100644 index 0000000..f44dbe1 --- /dev/null +++ b/lab8_CalebFontenot/DecimalToHex1.html @@ -0,0 +1,94 @@ + + + +DecimalToHex1.java + + + + +
/home/caleb/ASDV-Java/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/DecimalToHex1.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.lab8_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class DecimalToHex1 {
+    public static void main(String[] args) {
+        // Define vars
+        int inputDecimal,
+            outputHex = 0x0;
+        
+        // Create scanner
+        Scanner input = new Scanner(System.in);
+        
+        // Prompt for input
+        System.out.print("Enter a decimal value (0-15): ");
+        inputDecimal = input.nextInt();
+        
+        // Switch moment
+        switch (inputDecimal) {
+            case 0:
+                outputHex = 0x0; break;
+            case 1:
+                outputHex = 0x1; break;
+            case 2:
+                outputHex = 0x2; break;
+            case 3:
+                outputHex = 0x3; break;
+            case 4:
+                outputHex = 0x4; break;
+            case 5:
+                outputHex = 0x5; break;
+            case 6:
+                outputHex = 0x6; break;
+            case 7:
+                outputHex = 0x7; break;
+            case 8:
+                outputHex = 0x8; break;
+            case 9:
+                outputHex = 0x9; break;
+            case 10:
+                outputHex = 0xA; break;
+            case 11:
+                outputHex = 0xB; break;
+            case 12:
+                outputHex = 0xC; break;
+            case 13:
+                outputHex = 0xD; break;
+            case 14:
+                outputHex = 0xE; break;
+            case 15:
+                outputHex = 0xF; break;
+                
+        }
+        
+        // Output
+        System.out.println("The hex value is " + String.format("%x", outputHex));
+    }
+}
+
+
+ diff --git a/lab8_CalebFontenot/DecimalToHex2.html b/lab8_CalebFontenot/DecimalToHex2.html new file mode 100644 index 0000000..b2cb6e8 --- /dev/null +++ b/lab8_CalebFontenot/DecimalToHex2.html @@ -0,0 +1,93 @@ + + + +DecimalToHex2.java + + + + +
/home/caleb/ASDV-Java/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/DecimalToHex2.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.lab8_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class DecimalToHex2 {
+
+    public static void main(String[] args) {
+        // Define vars
+        int inputDecimal,
+                outputHex = 0x0;
+
+        // Create scanner
+        Scanner input = new Scanner(System.in); 
+        
+        // Prompt for input        
+        System.out.print("Enter a decimal value (0-15): ");
+        inputDecimal = input.nextInt();
+                
+        // Switch moment
+        if (inputDecimal == 0) {
+            outputHex = 0x0;
+        } else if (inputDecimal == 1) {
+            outputHex = 0x1;
+        } else if (inputDecimal == 2) {
+            outputHex = 0x2;
+        } else if (inputDecimal == 3) {
+            outputHex = 0x3;
+        } else if (inputDecimal == 4) {
+            outputHex = 0x4;
+        } else if (inputDecimal == 5) {
+            outputHex = 0x5;
+        } else if (inputDecimal == 6) {
+            outputHex = 0x6;
+        } else if (inputDecimal == 7) {
+            outputHex = 0x7;
+        } else if (inputDecimal == 8) {
+            outputHex = 0x8;
+        } else if (inputDecimal == 9) {
+            outputHex = 0x9;
+        } else if (inputDecimal == 10) {
+            outputHex = 0xA;
+        } else if (inputDecimal == 11) {
+            outputHex = 0xB;
+        } else if (inputDecimal == 12) {
+            outputHex = 0xC;
+        } else if (inputDecimal == 13) {
+            outputHex = 0xD;
+        } else if (inputDecimal == 14) {
+            outputHex = 0xE;
+        } else if (inputDecimal == 15) {
+            outputHex = 0xF;
+        }
+
+        // Output
+        System.out.println("The hex value is " + String.format("%x", outputHex));
+    }
+}
+
+
+ diff --git a/lab8_CalebFontenot/Switch1.html b/lab8_CalebFontenot/Switch1.html new file mode 100644 index 0000000..a156d11 --- /dev/null +++ b/lab8_CalebFontenot/Switch1.html @@ -0,0 +1,63 @@ + + + +Switch1.java + + + + +
/home/caleb/ASDV-Java/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Switch1.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.lab8_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class Switch1 {
+    public static void main(String[] args) {
+        // Create scanner
+        Scanner input = new Scanner(System.in);
+        
+        System.out.print("Enter a year to tell you a Chinese joke: ");
+        int year = input.nextInt();
+        
+        switch (year % 12) {
+            case 0: System.out.println("monkey"); break;
+            case 1: System.out.println("rooster"); break;
+            case 2: System.out.println("dog"); break;
+            case 3: System.out.println("pig"); break;
+            case 4: System.out.println("rat"); break;
+            case 5: System.out.println("ox"); break;
+            case 6: System.out.println("tiger"); break;
+            case 7: System.out.println("rabbit"); break;
+            case 8: System.out.println("dragon"); break;
+            case 9: System.out.println("snake"); break;
+            case 10: System.out.println("horse"); break;
+            case 11: System.out.println("sheep"); break;
+        }
+    }
+}
+
+
+ diff --git a/lab8_CalebFontenot/Switch1ConvertedToIfElse.html b/lab8_CalebFontenot/Switch1ConvertedToIfElse.html new file mode 100644 index 0000000..f57cf24 --- /dev/null +++ b/lab8_CalebFontenot/Switch1ConvertedToIfElse.html @@ -0,0 +1,73 @@ + + + +Switch1ConvertedToIfElse.java + + + + +
/home/caleb/ASDV-Java/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Switch1ConvertedToIfElse.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.lab8_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class Switch1ConvertedToIfElse {
+    public static void main(String[] args) {
+        // Create scanner
+        Scanner input = new Scanner(System.in);
+        
+        System.out.print("Enter a year to tell you a Chinese joke: ");
+        int year = input.nextInt();
+        
+        if (year == 0)
+            System.out.println("monkey");
+        else if (year == 1)    
+            System.out.println("rooster");
+        else if (year == 2)    
+            System.out.println("dog");
+        else if (year == 3)    
+            System.out.println("pig");
+        else if (year == 4)    
+            System.out.println("rat");
+        else if (year == 5)   
+            System.out.println("ox");
+        else if (year == 6)   
+            System.out.println("tiger");
+        else if (year == 7)   
+            System.out.println("rabbit");
+        else if (year == 8)   
+            System.out.println("dragon");
+        else if (year == 9)   
+            System.out.println("snake");
+        else if (year == 10)   
+            System.out.println("horse");
+        else if (year == 11)   
+            System.out.println("sheep");
+    }
+}
+
+
+ diff --git a/lab8_CalebFontenot/Switch2.html b/lab8_CalebFontenot/Switch2.html new file mode 100644 index 0000000..434a36f --- /dev/null +++ b/lab8_CalebFontenot/Switch2.html @@ -0,0 +1,50 @@ + + + +Switch2.java + + + + +
/home/caleb/ASDV-Java/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Switch2.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.lab8_calebfontenot;
+
+/**
+ *
+ * @author caleb
+ */
+public class Switch2 {
+    public static void main(String[] args) {
+        // Define vars
+        int x = 1, a = 3;
+        switch (a) {
+            case 1: x += 5;
+            case 2: x += 10;
+            case 3: x += 16;
+            case 4: x+= 34;
+        }
+        System.out.println(x + ", " + a);
+    }
+}
+
+
+ diff --git a/lab8_CalebFontenot/Switch3.html b/lab8_CalebFontenot/Switch3.html new file mode 100644 index 0000000..96ecd1e --- /dev/null +++ b/lab8_CalebFontenot/Switch3.html @@ -0,0 +1,92 @@ + + + +Switch3.java + + + + +
/home/caleb/ASDV-Java/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Switch3.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.lab8_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class Switch3 {
+
+    public static void main(String[] args) {
+        // Define vars
+        int dayOfWeekInt;
+        String dayOfWeekString = "nullday",
+                ordinal = "0th";
+
+        // Create scanner
+        Scanner input = new Scanner(System.in);
+
+        // Prompt for input
+        System.out.print("Enter a number that signifies a day of the week: ");
+        dayOfWeekInt = input.nextInt();
+
+        // Switch moment
+        switch (dayOfWeekInt) {
+            case 1:
+                dayOfWeekString = "Sunday";
+                ordinal = "1st";
+                break;
+            case 2:
+                dayOfWeekString = "Monday";
+                ordinal = "2nd";
+                break;
+            case 3:
+                dayOfWeekString = "Tuesday";
+                ordinal = "3rd";
+                break;
+            case 4:
+                dayOfWeekString = "Wednesday";
+                ordinal = "4th";
+                break;
+            case 5:
+                dayOfWeekString = "Thursday";
+                ordinal = "5th";
+                break;
+            case 6:
+                dayOfWeekString = "Friday";
+                ordinal = "6th";
+                break;
+            case 7:
+                dayOfWeekString = "Saturday";
+                ordinal = "7th";
+                break;
+        }
+        // Print output
+        if (dayOfWeekInt > 7)
+            System.out.println("That number is too high.");
+        else
+            System.out.println(dayOfWeekString + " is the " + ordinal + " day of the week.");
+    }
+}
+
+
+ diff --git a/lab8_CalebFontenot/Switch3ConvertedToIfElse.html b/lab8_CalebFontenot/Switch3ConvertedToIfElse.html new file mode 100644 index 0000000..2d7585c --- /dev/null +++ b/lab8_CalebFontenot/Switch3ConvertedToIfElse.html @@ -0,0 +1,86 @@ + + + +Switch3ConvertedToIfElse.java + + + + +
/home/caleb/ASDV-Java/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Switch3ConvertedToIfElse.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.lab8_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class Switch3ConvertedToIfElse {
+
+    public static void main(String[] args) {
+        // Define vars
+        int dayOfWeekInt;
+        String dayOfWeekString = "nullday",
+                ordinal = "0th";
+
+        // Create scanner
+        Scanner input = new Scanner(System.in);
+
+        // Prompt for input
+        System.out.print("Enter a number that signifies a day of the week: ");
+        dayOfWeekInt = input.nextInt();
+
+        // No longer Switch moment
+        if (dayOfWeekInt == 1) {
+            dayOfWeekString = "Sunday";
+            ordinal = "1st";
+        } else if (dayOfWeekInt == 2) {
+            dayOfWeekString = "Monday";
+            ordinal = "2nd";
+        } else if (dayOfWeekInt == 3) {
+            dayOfWeekString = "Tuesday";
+            ordinal = "3rd";
+        } else if (dayOfWeekInt == 4) {
+            dayOfWeekString = "Wednesday";
+            ordinal = "4th";
+        } else if (dayOfWeekInt == 5) {
+            dayOfWeekString = "Thursday";
+            ordinal = "5th";
+        } else if (dayOfWeekInt == 6) {
+            dayOfWeekString = "Friday";
+            ordinal = "6th";
+        } else if (dayOfWeekInt == 7) {
+            dayOfWeekString = "Saturday";
+                    ordinal = "7th";
+        }
+
+        // Print output
+        if (dayOfWeekInt > 7) {
+            System.out.println("That number is too high.");
+        } else {
+            System.out.println(dayOfWeekString + " is the " + ordinal + " day of the week.");
+        }
+    }
+}
+
+
+ diff --git a/lab8_CalebFontenot/Switch4.html b/lab8_CalebFontenot/Switch4.html new file mode 100644 index 0000000..04080ae --- /dev/null +++ b/lab8_CalebFontenot/Switch4.html @@ -0,0 +1,80 @@ + + + +Switch4.java + + + + +
/home/caleb/ASDV-Java/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Switch4.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.lab8_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class Switch4 {
+
+    public static void main(String[] args) {
+        // Define vars
+        String dayOfWeekString = "Nullday",
+                ordinal = "0th";
+
+        // Create scanner
+        Scanner input = new Scanner(System.in);
+
+        // Prompt for input
+        System.out.print("Enter a day of the week (Case-Sensitive): ");
+        dayOfWeekString = input.next();
+
+        // Switch moment
+        switch (dayOfWeekString) {
+            case "Sunday":
+                ordinal = "1st";
+                break;
+            case "Monday":
+                ordinal = "2nd";
+                break;
+            case "Tuesday":
+                ordinal = "3rd";
+                break;
+            case "Wednesday":
+                ordinal = "4th";
+                break;
+            case "Thursday":
+                ordinal = "5th";
+                break;
+            case "Friday":
+                ordinal = "6th";
+                break;
+            case "Saturday":
+                ordinal = "7th";
+                break;
+        }
+        // Print output
+        System.out.println(dayOfWeekString + " is the " + ordinal + " day of the week.");
+    }
+}
+
+
+ diff --git a/lab8_CalebFontenot/lab8-2-1.pdf b/lab8_CalebFontenot/lab8-2-1.pdf new file mode 100644 index 0000000..223f5c8 Binary files /dev/null and b/lab8_CalebFontenot/lab8-2-1.pdf differ diff --git a/lab8_CalebFontenot/pom.xml b/lab8_CalebFontenot/pom.xml new file mode 100644 index 0000000..230a03e --- /dev/null +++ b/lab8_CalebFontenot/pom.xml @@ -0,0 +1,14 @@ + + + 4.0.0 + com.calebfontenot + lab8_CalebFontenot + 1.0-SNAPSHOT + jar + + UTF-8 + 18 + 18 + com.calebfontenot.lab8_calebfontenot.Lab8_CalebFontenot + + \ No newline at end of file diff --git a/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/ConditionalOperator1.java b/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/ConditionalOperator1.java new file mode 100644 index 0000000..2ac133f --- /dev/null +++ b/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/ConditionalOperator1.java @@ -0,0 +1,26 @@ +/* + * 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.lab8_calebfontenot; + +import java.util.Scanner; + +/** + * + * @author caleb + */ +public class ConditionalOperator1 { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + + System.out.print("please enter an even number: "); + int number = scan.nextInt(); + if ( number % 2 == 0 ) + System.out.print("\n" + number + " fufills the request!"); + else + System.out.print("\n" + number + " does not fufill the request!"); + + System.out.println(number % 2 == 0 ? " yes sir!" : " no sir!"); + } +} diff --git a/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/ConditionalOperator2.java b/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/ConditionalOperator2.java new file mode 100644 index 0000000..a4eed18 --- /dev/null +++ b/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/ConditionalOperator2.java @@ -0,0 +1,19 @@ +/* + * 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.lab8_calebfontenot; + +/** + * + * @author caleb + */ +public class ConditionalOperator2 { + public static void main(String[] args) { + java.util.Scanner input = new java.util.Scanner(System.in); + double x = input.nextDouble(); + double y = input.nextDouble(); + double z = input.nextDouble(); + System.out.println((x < y && y < z) ? "sorted" : "not sorted"); + } +} diff --git a/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/ConditionalOperator3.java b/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/ConditionalOperator3.java new file mode 100644 index 0000000..87cb872 --- /dev/null +++ b/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/ConditionalOperator3.java @@ -0,0 +1,19 @@ +/* + * 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.lab8_calebfontenot; + +/** + * + * @author caleb + */ +public class ConditionalOperator3 { + public static void main(String[] args) { + java.util.Scanner input = new java.util.Scanner(System.in); + double x = input.nextDouble(); + double y = input.nextDouble(); + double z = input.nextDouble(); + System.out.println((x < y && y < z) ? 100 : 200); + } +} diff --git a/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/ConditionalOperator4.java b/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/ConditionalOperator4.java new file mode 100644 index 0000000..4900bc1 --- /dev/null +++ b/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/ConditionalOperator4.java @@ -0,0 +1,26 @@ +/* + * 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.lab8_calebfontenot; + +import java.util.Scanner; + +/** + * + * @author caleb + */ +public class ConditionalOperator4 { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + + System.out.print("please enter an even number: "); + int number = scan.nextInt(); + System.out.print("\n" + number + ( number % 2 == 0 ? " fufills the request!" : " does not fufill the request!")); + + if (number % 2 == 0) + System.out.println(" yes sir!"); + else + System.out.println(" no sir!"); + } +} diff --git a/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/DecimalToHex1.java b/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/DecimalToHex1.java new file mode 100644 index 0000000..8d06dca --- /dev/null +++ b/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/DecimalToHex1.java @@ -0,0 +1,66 @@ +/* + * 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.lab8_calebfontenot; + +import java.util.Scanner; + +/** + * + * @author caleb + */ +public class DecimalToHex1 { + public static void main(String[] args) { + // Define vars + int inputDecimal, + outputHex = 0x0; + + // Create scanner + Scanner input = new Scanner(System.in); + + // Prompt for input + System.out.print("Enter a decimal value (0-15): "); + inputDecimal = input.nextInt(); + + // Switch moment + switch (inputDecimal) { + case 0: + outputHex = 0x0; break; + case 1: + outputHex = 0x1; break; + case 2: + outputHex = 0x2; break; + case 3: + outputHex = 0x3; break; + case 4: + outputHex = 0x4; break; + case 5: + outputHex = 0x5; break; + case 6: + outputHex = 0x6; break; + case 7: + outputHex = 0x7; break; + case 8: + outputHex = 0x8; break; + case 9: + outputHex = 0x9; break; + case 10: + outputHex = 0xA; break; + case 11: + outputHex = 0xB; break; + case 12: + outputHex = 0xC; break; + case 13: + outputHex = 0xD; break; + case 14: + outputHex = 0xE; break; + case 15: + outputHex = 0xF; break; + + } + + // Output + System.out.println("The hex value is " + String.format("%x", outputHex)); + } +} diff --git a/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/DecimalToHex2.java b/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/DecimalToHex2.java new file mode 100644 index 0000000..e1eb8d1 --- /dev/null +++ b/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/DecimalToHex2.java @@ -0,0 +1,65 @@ +/* + * 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.lab8_calebfontenot; + +import java.util.Scanner; + +/** + * + * @author caleb + */ +public class DecimalToHex2 { + + public static void main(String[] args) { + // Define vars + int inputDecimal, + outputHex = 0x0; + + // Create scanner + Scanner input = new Scanner(System.in); + + // Prompt for input + System.out.print("Enter a decimal value (0-15): "); + inputDecimal = input.nextInt(); + + // Switch moment + if (inputDecimal == 0) { + outputHex = 0x0; + } else if (inputDecimal == 1) { + outputHex = 0x1; + } else if (inputDecimal == 2) { + outputHex = 0x2; + } else if (inputDecimal == 3) { + outputHex = 0x3; + } else if (inputDecimal == 4) { + outputHex = 0x4; + } else if (inputDecimal == 5) { + outputHex = 0x5; + } else if (inputDecimal == 6) { + outputHex = 0x6; + } else if (inputDecimal == 7) { + outputHex = 0x7; + } else if (inputDecimal == 8) { + outputHex = 0x8; + } else if (inputDecimal == 9) { + outputHex = 0x9; + } else if (inputDecimal == 10) { + outputHex = 0xA; + } else if (inputDecimal == 11) { + outputHex = 0xB; + } else if (inputDecimal == 12) { + outputHex = 0xC; + } else if (inputDecimal == 13) { + outputHex = 0xD; + } else if (inputDecimal == 14) { + outputHex = 0xE; + } else if (inputDecimal == 15) { + outputHex = 0xF; + } + + // Output + System.out.println("The hex value is " + String.format("%x", outputHex)); + } +} diff --git a/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Lab8_CalebFontenot.java b/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Lab8_CalebFontenot.java new file mode 100644 index 0000000..8cbfe86 --- /dev/null +++ b/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Lab8_CalebFontenot.java @@ -0,0 +1,17 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Project/Maven2/JavaApp/src/main/java/${packagePath}/${mainClassName}.java to edit this template + */ + +package com.calebfontenot.lab8_calebfontenot; + +/** + * + * @author caleb + */ +public class Lab8_CalebFontenot { + + public static void main(String[] args) { + System.out.println("Hello World!"); + } +} diff --git a/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Switch1.java b/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Switch1.java new file mode 100644 index 0000000..86758b9 --- /dev/null +++ b/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Switch1.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 com.calebfontenot.lab8_calebfontenot; + +import java.util.Scanner; + +/** + * + * @author caleb + */ +public class Switch1 { + public static void main(String[] args) { + // Create scanner + Scanner input = new Scanner(System.in); + + System.out.print("Enter a year to tell you a Chinese joke: "); + int year = input.nextInt(); + + switch (year % 12) { + case 0: System.out.println("monkey"); break; + case 1: System.out.println("rooster"); break; + case 2: System.out.println("dog"); break; + case 3: System.out.println("pig"); break; + case 4: System.out.println("rat"); break; + case 5: System.out.println("ox"); break; + case 6: System.out.println("tiger"); break; + case 7: System.out.println("rabbit"); break; + case 8: System.out.println("dragon"); break; + case 9: System.out.println("snake"); break; + case 10: System.out.println("horse"); break; + case 11: System.out.println("sheep"); break; + } + } +} diff --git a/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Switch1ConvertedToIfElse.java b/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Switch1ConvertedToIfElse.java new file mode 100644 index 0000000..d0eb1a2 --- /dev/null +++ b/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Switch1ConvertedToIfElse.java @@ -0,0 +1,46 @@ +/* + * 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.lab8_calebfontenot; + +import java.util.Scanner; + +/** + * + * @author caleb + */ +public class Switch1ConvertedToIfElse { + public static void main(String[] args) { + // Create scanner + Scanner input = new Scanner(System.in); + + System.out.print("Enter a year to tell you a Chinese joke: "); + int year = input.nextInt(); + + if (year == 0) + System.out.println("monkey"); + else if (year == 1) + System.out.println("rooster"); + else if (year == 2) + System.out.println("dog"); + else if (year == 3) + System.out.println("pig"); + else if (year == 4) + System.out.println("rat"); + else if (year == 5) + System.out.println("ox"); + else if (year == 6) + System.out.println("tiger"); + else if (year == 7) + System.out.println("rabbit"); + else if (year == 8) + System.out.println("dragon"); + else if (year == 9) + System.out.println("snake"); + else if (year == 10) + System.out.println("horse"); + else if (year == 11) + System.out.println("sheep"); + } +} diff --git a/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Switch2.java b/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Switch2.java new file mode 100644 index 0000000..6c6f62e --- /dev/null +++ b/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Switch2.java @@ -0,0 +1,23 @@ +/* + * 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.lab8_calebfontenot; + +/** + * + * @author caleb + */ +public class Switch2 { + public static void main(String[] args) { + // Define vars + int x = 1, a = 3; + switch (a) { + case 1: x += 5; + case 2: x += 10; + case 3: x += 16; + case 4: x+= 34; + } + System.out.println(x + ", " + a); + } +} diff --git a/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Switch3.java b/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Switch3.java new file mode 100644 index 0000000..add5415 --- /dev/null +++ b/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Switch3.java @@ -0,0 +1,65 @@ +/* + * 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.lab8_calebfontenot; + +import java.util.Scanner; + +/** + * + * @author caleb + */ +public class Switch3 { + + public static void main(String[] args) { + // Define vars + int dayOfWeekInt; + String dayOfWeekString = "nullday", + ordinal = "0th"; + + // Create scanner + Scanner input = new Scanner(System.in); + + // Prompt for input + System.out.print("Enter a number that signifies a day of the week: "); + dayOfWeekInt = input.nextInt(); + + // Switch moment + switch (dayOfWeekInt) { + case 1: + dayOfWeekString = "Sunday"; + ordinal = "1st"; + break; + case 2: + dayOfWeekString = "Monday"; + ordinal = "2nd"; + break; + case 3: + dayOfWeekString = "Tuesday"; + ordinal = "3rd"; + break; + case 4: + dayOfWeekString = "Wednesday"; + ordinal = "4th"; + break; + case 5: + dayOfWeekString = "Thursday"; + ordinal = "5th"; + break; + case 6: + dayOfWeekString = "Friday"; + ordinal = "6th"; + break; + case 7: + dayOfWeekString = "Saturday"; + ordinal = "7th"; + break; + } + // Print output + if (dayOfWeekInt > 7) + System.out.println("That number is too high."); + else + System.out.println(dayOfWeekString + " is the " + ordinal + " day of the week."); + } +} diff --git a/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Switch3ConvertedToIfElse.java b/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Switch3ConvertedToIfElse.java new file mode 100644 index 0000000..4a19498 --- /dev/null +++ b/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Switch3ConvertedToIfElse.java @@ -0,0 +1,59 @@ +/* + * 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.lab8_calebfontenot; + +import java.util.Scanner; + +/** + * + * @author caleb + */ +public class Switch3ConvertedToIfElse { + + public static void main(String[] args) { + // Define vars + int dayOfWeekInt; + String dayOfWeekString = "nullday", + ordinal = "0th"; + + // Create scanner + Scanner input = new Scanner(System.in); + + // Prompt for input + System.out.print("Enter a number that signifies a day of the week: "); + dayOfWeekInt = input.nextInt(); + + // No longer Switch moment + if (dayOfWeekInt == 1) { + dayOfWeekString = "Sunday"; + ordinal = "1st"; + } else if (dayOfWeekInt == 2) { + dayOfWeekString = "Monday"; + ordinal = "2nd"; + } else if (dayOfWeekInt == 3) { + dayOfWeekString = "Tuesday"; + ordinal = "3rd"; + } else if (dayOfWeekInt == 4) { + dayOfWeekString = "Wednesday"; + ordinal = "4th"; + } else if (dayOfWeekInt == 5) { + dayOfWeekString = "Thursday"; + ordinal = "5th"; + } else if (dayOfWeekInt == 6) { + dayOfWeekString = "Friday"; + ordinal = "6th"; + } else if (dayOfWeekInt == 7) { + dayOfWeekString = "Saturday"; + ordinal = "7th"; + } + + // Print output + if (dayOfWeekInt > 7) { + System.out.println("That number is too high."); + } else { + System.out.println(dayOfWeekString + " is the " + ordinal + " day of the week."); + } + } +} diff --git a/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Switch4.java b/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Switch4.java new file mode 100644 index 0000000..1d66e4c --- /dev/null +++ b/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Switch4.java @@ -0,0 +1,54 @@ +/* + * 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.lab8_calebfontenot; + +import java.util.Scanner; + +/** + * + * @author caleb + */ +public class Switch4 { + + public static void main(String[] args) { + // Define vars + String dayOfWeekString = "Nullday", + ordinal = "0th"; + + // Create scanner + Scanner input = new Scanner(System.in); + + // Prompt for input + System.out.print("Enter a day of the week (Case-Sensitive): "); + dayOfWeekString = input.next(); + + // Switch moment + switch (dayOfWeekString) { + case "Sunday": + ordinal = "1st"; + break; + case "Monday": + ordinal = "2nd"; + break; + case "Tuesday": + ordinal = "3rd"; + break; + case "Wednesday": + ordinal = "4th"; + break; + case "Thursday": + ordinal = "5th"; + break; + case "Friday": + ordinal = "6th"; + break; + case "Saturday": + ordinal = "7th"; + break; + } + // Print output + System.out.println(dayOfWeekString + " is the " + ordinal + " day of the week."); + } +}