begin lab 6
This commit is contained in:
parent
9e597946c2
commit
e28eec5c61
2
.gitignore
vendored
2
.gitignore
vendored
@ -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/
|
||||
|
BIN
Semester 2/.DS_Store
vendored
Normal file
BIN
Semester 2/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
Semester 2/Assignments/.DS_Store
vendored
Normal file
BIN
Semester 2/Assignments/.DS_Store
vendored
Normal file
Binary file not shown.
14
Semester 2/Assignments/Exceptions/pom.xml
Normal file
14
Semester 2/Assignments/Exceptions/pom.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.mycompany</groupId>
|
||||
<artifactId>Exceptions</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<exec.mainClass>com.mycompany.exceptions.Exceptions</exec.mainClass>
|
||||
</properties>
|
||||
</project>
|
@ -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!");
|
||||
}
|
||||
}
|
@ -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 ...");
|
||||
}
|
||||
}
|
@ -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<String> a = new ArrayList();
|
||||
ArrayList<String> 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));
|
||||
}
|
||||
}
|
Binary file not shown.
14
Semester 2/Assignments/lab6-Exceptions_CalebFontenot/pom.xml
Normal file
14
Semester 2/Assignments/lab6-Exceptions_CalebFontenot/pom.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.mycompany</groupId>
|
||||
<artifactId>lab6-Exceptions_CalebFontenot</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<exec.mainClass>com.mycompany.lab6.exceptions_calebfontenot.Lab6Exceptions_CalebFontenot</exec.mainClass>
|
||||
</properties>
|
||||
</project>
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -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!");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user