begin lab 6

This commit is contained in:
Caleb Fontenot
2023-03-14 12:26:51 -05:00
parent 9e597946c2
commit e28eec5c61
12 changed files with 179 additions and 0 deletions

View 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>

View File

@@ -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());
}
}
}

View File

@@ -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!");
}
}