ASDV-Java/Semester 2/Assignments/lab6-Exceptions_CalebFontenot/Printed HTMLs/CircleWithChehckedException.html

75 lines
4.4 KiB
HTML
Raw Normal View History

2023-03-21 11:43:38 -05:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>CircleWithCheckedException.java</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
<!--
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace}
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace}
table {color: #888888; background-color: #313335; font-family: monospace}
.number {color: #6897bb}
.string {color: #6a8759}
.comment {color: #808080}
.whitespace {color: #505050}
.ST0 {color: #808080; font-family: monospace; font-weight: bold}
.literal {color: #cc7832}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 2/Assignments/lab6-Exceptions_CalebFontenot/src/main/java/com/mycompany/lab6/exceptions_calebfontenot/CircleWithCheckedException.java</td></tr></table>
<pre>
<span class="comment">/*</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template</span>
<span class="comment"> */</span>
<span class="literal">package</span> com.mycompany.lab6.exceptions_calebfontenot;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST0">@author</span> <span class="comment">calebfontenot</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> CircleWithCheckedException {
<span class="literal">private</span> <span class="literal">double</span> radius;
<span class="literal">public</span> CircleWithCheckedException() <span class="literal">throws</span> Exception
{
<span class="literal">this</span>(<span class="number">1.0</span>);
}
<span class="literal">public</span> CircleWithCheckedException(<span class="literal">double</span> radius) <span class="literal">throws</span> Exception
{
<span class="literal">if</span> (radius &lt; <span class="number">0</span>) {
<span class="literal">throw</span> <span class="literal">new</span> Exception(<span class="string">&quot;</span><span class="string">Radius cannot be negative.</span><span class="string">&quot;</span>);
}
<span class="literal">this</span>.radius = radius;
}
<span class="literal">public</span> <span class="literal">double</span> getRadius() {
<span class="literal">return</span> radius;
}
<span class="literal">public</span> <span class="literal">void</span> setRadius(<span class="literal">double</span> radius) <span class="literal">throws</span> Exception {
<span class="literal">if</span> (radius &lt; <span class="number">0</span>) {
<span class="literal">throw</span> <span class="literal">new</span> Exception(<span class="string">&quot;</span><span class="string">Radius cannot be negative.</span><span class="string">&quot;</span>);
}
<span class="literal">this</span>.radius = radius;
}
@Override
<span class="literal">public</span> String toString() {
<span class="literal">return</span> <span class="string">&quot;</span><span class="string">CircleWithCheckedException{</span><span class="string">&quot;</span> + <span class="string">&quot;</span><span class="string">radius=</span><span class="string">&quot;</span> + radius + <span class="string">&#39;</span><span class="string">}</span><span class="string">&#39;</span>;
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args) {
<span class="literal">try</span> {
System.out.println(<span class="literal">new</span> CircleWithCheckedException(<span class="number">5</span>));
System.out.println(<span class="literal">new</span> CircleWithCheckedException(-<span class="number">5</span>));
System.out.println(<span class="literal">new</span> CircleWithCheckedException(<span class="number">10</span>));
} <span class="literal">catch</span> (Exception ex) {
System.err.println(<span class="string">&quot;</span><span class="string">an exception occured: </span><span class="string">&quot;</span> + ex.getMessage());
}
}
}
</pre></body>
</html>