diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..6f5c282 Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore index b8dcd6f..2e115e5 100644 --- a/.gitignore +++ b/.gitignore @@ -113,3 +113,5 @@ /Semester 2/Assignments/test/target/ /Semester 2/Assignments/lab5__CalebFontenot/target/ /Semester 2/Assignments/MP4_CalebFontenot/target/ +/Semester 2/Assignments/Exceptions/target/ +/Semester 2/Assignments/lab6-Exceptions_CalebFontenot/target/ diff --git a/Semester 2/.DS_Store b/Semester 2/.DS_Store new file mode 100644 index 0000000..237624c Binary files /dev/null and b/Semester 2/.DS_Store differ diff --git a/Semester 2/Assignments/.DS_Store b/Semester 2/Assignments/.DS_Store new file mode 100644 index 0000000..9052ce8 Binary files /dev/null and b/Semester 2/Assignments/.DS_Store differ diff --git a/Semester 2/Assignments/Exceptions/pom.xml b/Semester 2/Assignments/Exceptions/pom.xml new file mode 100644 index 0000000..f18e002 --- /dev/null +++ b/Semester 2/Assignments/Exceptions/pom.xml @@ -0,0 +1,14 @@ + + + 4.0.0 + com.mycompany + Exceptions + 1.0-SNAPSHOT + jar + + UTF-8 + 17 + 17 + com.mycompany.exceptions.Exceptions + + \ No newline at end of file diff --git a/Semester 2/Assignments/Exceptions/src/main/java/com/mycompany/exceptions/Exceptions.java b/Semester 2/Assignments/Exceptions/src/main/java/com/mycompany/exceptions/Exceptions.java new file mode 100644 index 0000000..67da5ec --- /dev/null +++ b/Semester 2/Assignments/Exceptions/src/main/java/com/mycompany/exceptions/Exceptions.java @@ -0,0 +1,16 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + */ + +package com.mycompany.exceptions; + +/** + * + * @author calebfontenot + */ +public class Exceptions { + + public static void main(String[] args) { + System.out.println("Hello World!"); + } +} diff --git a/Semester 2/Assignments/Exceptions/src/main/java/com/mycompany/exceptions/QuotientWithException.java b/Semester 2/Assignments/Exceptions/src/main/java/com/mycompany/exceptions/QuotientWithException.java new file mode 100644 index 0000000..2226e40 --- /dev/null +++ b/Semester 2/Assignments/Exceptions/src/main/java/com/mycompany/exceptions/QuotientWithException.java @@ -0,0 +1,41 @@ +/* + * 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.mycompany.exceptions; + +/** + * + * @author calebfontenot + */ +import java.util.Scanner; + +public class QuotientWithException { + public static int quotient(int number1, int number2) { + if (number2 == 0) + throw new ArithmeticException("Divisor cannot be zero"); + + return number1 / number2; + } + + public static void main(String[] args) { + Scanner input = new Scanner(System.in); + + // Prompt the user to enter two integers + System.out.print("Enter two integers: "); + int number1 = input.nextInt(); + int number2 = input.nextInt(); + + try { + int result = quotient(number1, number2); + System.out.println(number1 + " / " + number2 + " is " + + result); + } + catch (ArithmeticException ex) { + System.err.println("Exception: an integer " + + "cannot be divided by zero "); + } + + System.out.println("Execution continues ..."); + } +} diff --git a/Semester 2/Assignments/Exceptions/src/main/java/com/mycompany/exceptions/Yes.java b/Semester 2/Assignments/Exceptions/src/main/java/com/mycompany/exceptions/Yes.java new file mode 100644 index 0000000..55f5e3a --- /dev/null +++ b/Semester 2/Assignments/Exceptions/src/main/java/com/mycompany/exceptions/Yes.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.mycompany.exceptions; + +import java.util.ArrayList; + +/** + * + * @author calebfontenot + */ +public class Yes { + public static void main(String[] args) { + ArrayList a = new ArrayList(); + ArrayList b = null; + try { + a.add(new String("Hello, no issues here!")); + b.add(new String("Hello Exception!")); + } catch (NullPointerException ex) { + System.out.println("You cannot add a string to this ArrayList because the ArrayList is null."); + System.err.println(ex); + } + System.out.println(a.get(0)); + } +} diff --git a/Semester 2/Assignments/lab6-Exceptions_CalebFontenot/lab6-3-1.pdf b/Semester 2/Assignments/lab6-Exceptions_CalebFontenot/lab6-3-1.pdf new file mode 100644 index 0000000..9d6c5fb Binary files /dev/null and b/Semester 2/Assignments/lab6-Exceptions_CalebFontenot/lab6-3-1.pdf differ diff --git a/Semester 2/Assignments/lab6-Exceptions_CalebFontenot/pom.xml b/Semester 2/Assignments/lab6-Exceptions_CalebFontenot/pom.xml new file mode 100644 index 0000000..9e7bd67 --- /dev/null +++ b/Semester 2/Assignments/lab6-Exceptions_CalebFontenot/pom.xml @@ -0,0 +1,14 @@ + + + 4.0.0 + com.mycompany + lab6-Exceptions_CalebFontenot + 1.0-SNAPSHOT + jar + + UTF-8 + 17 + 17 + com.mycompany.lab6.exceptions_calebfontenot.Lab6Exceptions_CalebFontenot + + \ No newline at end of file diff --git a/Semester 2/Assignments/lab6-Exceptions_CalebFontenot/src/main/java/com/mycompany/lab6/exceptions_calebfontenot/CircleWithCheckedException.java b/Semester 2/Assignments/lab6-Exceptions_CalebFontenot/src/main/java/com/mycompany/lab6/exceptions_calebfontenot/CircleWithCheckedException.java new file mode 100644 index 0000000..d04ea05 --- /dev/null +++ b/Semester 2/Assignments/lab6-Exceptions_CalebFontenot/src/main/java/com/mycompany/lab6/exceptions_calebfontenot/CircleWithCheckedException.java @@ -0,0 +1,50 @@ +/* + * 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.mycompany.lab6.exceptions_calebfontenot; + +/** + * + * @author calebfontenot + */ +public class CircleWithCheckedException { + private double radius; + + public CircleWithCheckedException() throws Exception + { + this(1.0); + } + public CircleWithCheckedException(double radius) throws Exception + { + if (radius < 0) { + throw new Exception("Radius cannot be negative."); + } + this.radius = radius; + } + + public double getRadius() { + return radius; + } + public void setRadius(double radius) throws Exception { + if (radius < 0) { + throw new Exception("Radius cannot be negative."); + } + this.radius = radius; + } + + @Override + public String toString() { + return "CircleWithCheckedException{" + "radius=" + radius + '}'; + } + public static void main(String[] args) { + try { + System.out.println(new CircleWithCheckedException(5)); + System.out.println(new CircleWithCheckedException(-5)); + System.out.println(new CircleWithCheckedException(10)); + } catch (Exception ex) { + System.err.println("an exception occured: " + ex.getMessage()); + } + + } +} \ No newline at end of file diff --git a/Semester 2/Assignments/lab6-Exceptions_CalebFontenot/src/main/java/com/mycompany/lab6/exceptions_calebfontenot/Lab6Exceptions_CalebFontenot.java b/Semester 2/Assignments/lab6-Exceptions_CalebFontenot/src/main/java/com/mycompany/lab6/exceptions_calebfontenot/Lab6Exceptions_CalebFontenot.java new file mode 100644 index 0000000..dc7f80f --- /dev/null +++ b/Semester 2/Assignments/lab6-Exceptions_CalebFontenot/src/main/java/com/mycompany/lab6/exceptions_calebfontenot/Lab6Exceptions_CalebFontenot.java @@ -0,0 +1,16 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + */ + +package com.mycompany.lab6.exceptions_calebfontenot; + +/** + * + * @author calebfontenot + */ +public class Lab6Exceptions_CalebFontenot { + + public static void main(String[] args) { + System.out.println("Hello World!"); + } +}