diff --git a/lab6_CalebFontenot.zip b/lab6_CalebFontenot.zip new file mode 100644 index 0000000..1a28981 Binary files /dev/null and b/lab6_CalebFontenot.zip differ diff --git a/lab6_CalebFontenot/If1.html b/lab6_CalebFontenot/If1.html new file mode 100644 index 0000000..63bb151 --- /dev/null +++ b/lab6_CalebFontenot/If1.html @@ -0,0 +1,55 @@ + + + +If1.java + + + + +
/home/caleb/ASDV-Java/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/If1.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.lab6_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class If1 {
+    public static void main(String[] args)
+    {
+        System.out.println("Please type a positive number: ");
+        
+        /*
+        Observe that the varible scan is eliminated
+        Explanation: We create a new object by using "new Scanner" and
+        then the DOT (.) nextInt() uses that new object (new varibale) to read
+        */
+        int number = new Scanner(System.in).nextInt();
+        
+        if ( number >= 0 )
+            System.out.println("You typed a positive number! It was number " + number + "!");
+    }
+}
+
+
+ diff --git a/lab6_CalebFontenot/If2.html b/lab6_CalebFontenot/If2.html new file mode 100644 index 0000000..d96dce9 --- /dev/null +++ b/lab6_CalebFontenot/If2.html @@ -0,0 +1,47 @@ + + + +If2.java + + + + +
/home/caleb/ASDV-Java/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/If2.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.lab6_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class If2 {
+    public static void main(String[] args) {
+        System.out.println("Please type a positive number: ");
+        
+        if (new Scanner(System.in).nextInt() >= 0 )
+            System.out.println("Tou typed a positive number!");
+    }
+}
+
+
+ diff --git a/lab6_CalebFontenot/If3.html b/lab6_CalebFontenot/If3.html new file mode 100644 index 0000000..599629c --- /dev/null +++ b/lab6_CalebFontenot/If3.html @@ -0,0 +1,51 @@ + + + +If3.java + + + + +
/home/caleb/ASDV-Java/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/If3.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.lab6_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class If3 {
+    public static void main(String[] args) {
+        int number;
+        
+        System.out.println("Please type a positive number: ");
+        
+        if ( (number = new Scanner(System.in).nextInt() ) >= 0 )
+            System.out.println("Tou typed a positive number. It was number " + number + "!");
+        else
+            System.out.println("You typed a negative number. It was number " + number + "!");
+    }
+}
+
+
+ diff --git a/lab6_CalebFontenot/IfElse1.html b/lab6_CalebFontenot/IfElse1.html new file mode 100644 index 0000000..5365458 --- /dev/null +++ b/lab6_CalebFontenot/IfElse1.html @@ -0,0 +1,54 @@ + + + +IfElse1.java + + + + +
/home/caleb/ASDV-Java/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/IfElse1.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.lab6_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class IfElse1 {
+    public static void main(String[] args) {
+        System.out.println("Please type a positive number: ");
+        
+        /*
+        Observe that the variable scan is eliminated
+        Explanation: We create a new object by using "new Scanner" and
+        then the DOT (.) nextInt() uses that new object (new variable) to read.
+        */
+        int number = new Scanner(System.in).nextInt();
+        
+        if ( number >= 0 )
+            System.out.println("You typed a positive number! It was number " + number + "!");
+    }
+}
+
+
+ diff --git a/lab6_CalebFontenot/IfElse2.html b/lab6_CalebFontenot/IfElse2.html new file mode 100644 index 0000000..594bd68 --- /dev/null +++ b/lab6_CalebFontenot/IfElse2.html @@ -0,0 +1,59 @@ + + + +IfElse2.java + + + + +
/home/caleb/ASDV-Java/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/IfElse2.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.lab6_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class IfElse2 {
+    public static void main(String[] args) {
+        // Setup variables
+        int number;
+        
+        // Prompt for input
+        System.out.print("Please enter a even or odd number: ");
+        number = new Scanner(System.in).nextInt(); // Creates scanner just to read a value for number, but doesn't keep the scanner in memory.
+        
+        // Determine with if statement and Output
+        if ( number % 2 == 0 ) // An even number when divided by 2 will ALWAYS have a remainder that equals 0
+        {
+            System.out.println("You typed the EVEN number " + number);
+        }
+        else
+        {
+            System.out.println("You typed the ODD number " + number);
+        }
+    }
+}
+
+
+ diff --git a/lab6_CalebFontenot/IfElse3.html b/lab6_CalebFontenot/IfElse3.html new file mode 100644 index 0000000..1ff0abc --- /dev/null +++ b/lab6_CalebFontenot/IfElse3.html @@ -0,0 +1,60 @@ + + + +IfElse3.java + + + + +
/home/caleb/ASDV-Java/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/IfElse3.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.lab6_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class IfElse3 {
+    public static void main(String[] args) {
+        System.out.print("Please type today's temperature and I will comment on it: ");
+        Scanner scan = new Scanner(System.in);
+        double todaysTemperature = scan.nextDouble();
+        
+        if ( todaysTemperature >= 120)
+            System.out.println("Come on dude! Be serious!");
+        else if ( todaysTemperature >= 100)
+            System.out.println("Very, very hot at " + todaysTemperature + "!");
+        else if ( todaysTemperature >= 85)
+            System.out.println("hot at " + todaysTemperature);
+        else if ( todaysTemperature >= 70 )
+            System.out.println("Pleasant at " + todaysTemperature);
+        else if ( todaysTemperature >= 40 )
+            System.out.println("A bit cold at " + todaysTemperature);
+        else
+            System.out.println("bbbrrrrrrr at " + todaysTemperature + "!");
+        
+    }
+}
+
+
+ diff --git a/lab6_CalebFontenot/IfElse4.html b/lab6_CalebFontenot/IfElse4.html new file mode 100644 index 0000000..13a368d --- /dev/null +++ b/lab6_CalebFontenot/IfElse4.html @@ -0,0 +1,102 @@ + + + +IfElse4.java + + + + +
/home/caleb/ASDV-Java/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/IfElse4.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.lab6_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class IfElse4 {
+
+    static double inputPrompt() {
+        double grade;
+        System.out.print("Enter your exam grade for it to be letter graded: ");
+        grade = new Scanner(System.in).nextDouble();
+        return grade;
+    }    
+    static void ifLogic(double grade) {
+        // Use if else logic and output
+        if (grade > 100) {
+            System.out.println("Your grade seems too high, please try again...");
+            throw new IllegalArgumentException("Invalid grade entered!");
+        }
+        else if ( grade > 90)
+        {
+            System.out.println("Congrats! You got a " + grade + ", which means you got an A!");
+        }
+        else if ( grade > 80)
+        {
+            System.out.println("Good job! You got a " + grade + ", which means you got a B!");
+        }
+        else if ( grade > 70)
+        {
+            System.out.println("Not bad, you got a " + grade + ", which means you got a C.");
+        }
+        else if ( grade > 60)
+        {
+            System.out.println("You got a " + grade + ", which means you got a D.");
+        }
+        else if (grade < 0) {
+            System.out.println("Your grade seems too low, please try again...");
+            throw new IllegalArgumentException("Invalid grade entered!");
+        }
+        else 
+        {
+            System.out.println("Sorry, you got a " + grade + ", so you unfortunately got an F.");   
+        }
+    }
+
+    public static void main(String[] args) {
+        // Setup variables
+        double grade;
+        String letterGrade;
+        
+        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
+                grade = inputPrompt();
+                ifLogic(grade);
+                System.exit(0);
+        }
+            catch(Exception IllegalArgumentException) { // ifLogic failed, try again...
+                // Prompt for input
+                grade = inputPrompt();
+                ifLogic(grade);
+        }
+        }
+    }
+
+}
+
+
+ diff --git a/lab6_CalebFontenot/Lab6_CalebFontenot.html b/lab6_CalebFontenot/Lab6_CalebFontenot.html new file mode 100644 index 0000000..4ae2144 --- /dev/null +++ b/lab6_CalebFontenot/Lab6_CalebFontenot.html @@ -0,0 +1,49 @@ + + + +Lab6_CalebFontenot.java + + + + +
/home/caleb/ASDV-Java/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/Lab6_CalebFontenot.java
+
+/*
+ * 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.lab6_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class Lab6_CalebFontenot {
+
+    public static void main(String[] args)
+    {
+        System.out.println("Please type a positive number: ");
+        Scanner scan = new Scanner(System.in);
+        int number = scan.nextInt();
+
+        if (number >= 0) {
+            System.out.println("You typed a positive number! It was number " + number + "!");
+        }
+    }
+}
+
+
+ diff --git a/lab6_CalebFontenot/Triangle.html b/lab6_CalebFontenot/Triangle.html new file mode 100644 index 0000000..5bb8695 --- /dev/null +++ b/lab6_CalebFontenot/Triangle.html @@ -0,0 +1,68 @@ + + + +Triangle.java + + + + +
/home/caleb/ASDV-Java/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/Triangle.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.lab6_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class Triangle {
+    public static void main(String[] args) {
+        // Setup variables
+        double x1,
+               y1,
+               xIntercept;
+        
+       // Create scanner
+       Scanner input = new Scanner(System.in);
+       
+       // Prompt for input
+       System.out.print("Enter a point's x and y coords: ");
+       x1 = input.nextDouble();
+       y1 = input.nextDouble();
+       
+       // Calculate!
+       
+       // 2. Calculate x by -.5 and add 100 to that
+       xIntercept = ((-0.5 * x1) + 100);
+        System.out.println("x intercept is " + xIntercept);
+       // Check if y is inside of the triangle
+        
+       if (y1 <= xIntercept)
+       {
+           System.out.println(x1 +", "+ y1 + " is inside of the triangle!");
+       }
+       else
+       {
+           System.out.println(x1 +", "+ y1 + " is outside of the triangle!");
+       }
+    }
+}
+
+
+ diff --git a/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/If2.java b/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/If2.java new file mode 100644 index 0000000..27d7bdf --- /dev/null +++ b/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/If2.java @@ -0,0 +1,20 @@ +/* + * 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.lab6_calebfontenot; + +import java.util.Scanner; + +/** + * + * @author caleb + */ +public class If2 { + public static void main(String[] args) { + System.out.println("Please type a positive number: "); + + if (new Scanner(System.in).nextInt() >= 0 ) + System.out.println("Tou typed a positive number!"); + } +} diff --git a/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/If3.java b/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/If3.java new file mode 100644 index 0000000..617b291 --- /dev/null +++ b/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/If3.java @@ -0,0 +1,24 @@ +/* + * 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.lab6_calebfontenot; + +import java.util.Scanner; + +/** + * + * @author caleb + */ +public class If3 { + public static void main(String[] args) { + int number; + + System.out.println("Please type a positive number: "); + + if ( (number = new Scanner(System.in).nextInt() ) >= 0 ) + System.out.println("Tou typed a positive number. It was number " + number + "!"); + else + System.out.println("You typed a negative number. It was number " + number + "!"); + } +} diff --git a/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/IfElse1.java b/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/IfElse1.java new file mode 100644 index 0000000..0494a81 --- /dev/null +++ b/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/IfElse1.java @@ -0,0 +1,27 @@ +/* + * 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.lab6_calebfontenot; + +import java.util.Scanner; + +/** + * + * @author caleb + */ +public class IfElse1 { + public static void main(String[] args) { + System.out.println("Please type a positive number: "); + + /* + Observe that the variable scan is eliminated + Explanation: We create a new object by using "new Scanner" and + then the DOT (.) nextInt() uses that new object (new variable) to read. + */ + int number = new Scanner(System.in).nextInt(); + + if ( number >= 0 ) + System.out.println("You typed a positive number! It was number " + number + "!"); + } +} diff --git a/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/IfElse2.java b/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/IfElse2.java new file mode 100644 index 0000000..9098d18 --- /dev/null +++ b/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/IfElse2.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 com.calebfontenot.lab6_calebfontenot; + +import java.util.Scanner; + +/** + * + * @author caleb + */ +public class IfElse2 { + public static void main(String[] args) { + // Setup variables + int number; + + // Prompt for input + System.out.print("Please enter a even or odd number: "); + number = new Scanner(System.in).nextInt(); // Creates scanner just to read a value for number, but doesn't keep the scanner in memory. + + // Determine with if statement and Output + if ( number % 2 == 0 ) // An even number when divided by 2 will ALWAYS have a remainder that equals 0 + { + System.out.println("You typed the EVEN number " + number); + } + else + { + System.out.println("You typed the ODD number " + number); + } + } +} diff --git a/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/IfElse3.java b/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/IfElse3.java new file mode 100644 index 0000000..8b9af89 --- /dev/null +++ b/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/IfElse3.java @@ -0,0 +1,33 @@ +/* + * 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.lab6_calebfontenot; + +import java.util.Scanner; + +/** + * + * @author caleb + */ +public class IfElse3 { + public static void main(String[] args) { + System.out.print("Please type today's temperature and I will comment on it: "); + Scanner scan = new Scanner(System.in); + double todaysTemperature = scan.nextDouble(); + + if ( todaysTemperature >= 120) + System.out.println("Come on dude! Be serious!"); + else if ( todaysTemperature >= 100) + System.out.println("Very, very hot at " + todaysTemperature + "!"); + else if ( todaysTemperature >= 85) + System.out.println("hot at " + todaysTemperature); + else if ( todaysTemperature >= 70 ) + System.out.println("Pleasant at " + todaysTemperature); + else if ( todaysTemperature >= 40 ) + System.out.println("A bit cold at " + todaysTemperature); + else + System.out.println("bbbrrrrrrr at " + todaysTemperature + "!"); + + } +} 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 new file mode 100644 index 0000000..b8e1250 --- /dev/null +++ b/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/IfElse4.java @@ -0,0 +1,74 @@ +/* + * 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.lab6_calebfontenot; + +import java.util.Scanner; + +/** + * + * @author caleb + */ +public class IfElse4 { + + static double inputPrompt() { + double grade; + System.out.print("Enter your exam grade for it to be letter graded: "); + grade = new Scanner(System.in).nextDouble(); + return grade; + } + static void ifLogic(double grade) { + // Use if else logic and output + if (grade > 100) { + System.out.println("Your grade seems too high, please try again..."); + throw new IllegalArgumentException("Invalid grade entered!"); + } + else if ( grade > 90) + { + System.out.println("Congrats! You got a " + grade + ", which means you got an A!"); + } + else if ( grade > 80) + { + System.out.println("Good job! You got a " + grade + ", which means you got a B!"); + } + else if ( grade > 70) + { + System.out.println("Not bad, you got a " + grade + ", which means you got a C."); + } + else if ( grade > 60) + { + System.out.println("You got a " + grade + ", which means you got a D."); + } + else if (grade < 0) { + System.out.println("Your grade seems too low, please try again..."); + throw new IllegalArgumentException("Invalid grade entered!"); + } + else + { + System.out.println("Sorry, you got a " + grade + ", so you unfortunately got an F."); + } + } + + public static void main(String[] args) { + // Setup variables + double grade; + String letterGrade; + + while (true) { + // Call ifLogic function + try { + // Prompt for input + grade = inputPrompt(); + ifLogic(grade); + System.exit(0); + } + catch(Exception IllegalArgumentException) { // ifLogic failed, try again... + // Prompt for input + grade = inputPrompt(); + ifLogic(grade); + } + } + } + +} diff --git a/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/Triangle.java b/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/Triangle.java index 0bfba8a..6fbb85c 100644 --- a/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/Triangle.java +++ b/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/Triangle.java @@ -4,10 +4,41 @@ */ package com.calebfontenot.lab6_calebfontenot; +import java.util.Scanner; + /** * * @author caleb */ public class Triangle { - + public static void main(String[] args) { + // Setup variables + double x1, + y1, + xIntercept; + + // Create scanner + Scanner input = new Scanner(System.in); + + // Prompt for input + System.out.print("Enter a point's x and y coords: "); + x1 = input.nextDouble(); + y1 = input.nextDouble(); + + // Calculate! + + // 2. Calculate x by -.5 and add 100 to that + xIntercept = ((-0.5 * x1) + 100); + System.out.println("x intercept is " + xIntercept); + // Check if y is inside of the triangle + + if (y1 <= xIntercept) + { + System.out.println(x1 +", "+ y1 + " is inside of the triangle!"); + } + else + { + System.out.println(x1 +", "+ y1 + " is outside of the triangle!"); + } + } }