Reset author name to chosen name

This commit is contained in:
2025-10-19 21:55:26 -05:00
parent a3e71f9673
commit 03c2474f78
1825 changed files with 8916 additions and 8921 deletions

View File

@@ -0,0 +1,74 @@
<!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/chloe/ASDV-Java/Semester 2/Assignments/lab6-Exceptions_ChloeFontenot/src/main/java/com/mycompany/lab6/exceptions_chloefontenot/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_chloefontenot;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST0">@author</span> <span class="comment">chloefontenot</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>

View File

@@ -0,0 +1,40 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Lab6Exceptions_ChloeFontenot.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}
.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/chloe/ASDV-Java/Semester 2/Assignments/lab6-Exceptions_ChloeFontenot/src/main/java/com/mycompany/lab6/exceptions_chloefontenot/Lab6Exceptions_ChloeFontenot.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"> */</span>
<span class="literal">package</span> com.mycompany.lab6.exceptions_chloefontenot;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST0">@author</span> <span class="comment">chloefontenot</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> Lab6Exceptions_ChloeFontenot {
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args) {
System.out.println(<span class="string">&quot;</span><span class="string">Hello World!</span><span class="string">&quot;</span>);
}
}
</pre></body>
</html>

View File

@@ -0,0 +1,73 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>ProcessScoresInTextFile.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}
.string {color: #6a8759}
.number {color: #6897bb}
.comment {color: #808080}
.whitespace {color: #505050}
.ST2 {color: #ffc66d; font-family: monospace; font-style: italic}
.ST3 {color: #9876aa; font-family: monospace; font-style: italic}
.ST1 {color: #808080; font-family: monospace; font-weight: bold}
.ST0 {color: #287bde}
.literal {color: #cc7832}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/chloe/ASDV-Java/Semester 2/Assignments/lab6-Exceptions_ChloeFontenot/src/main/java/com/mycompany/lab6/exceptions_chloefontenot/ProcessScoresInTextFile.java</td></tr></table>
<pre>
<span class="comment">/*</span>
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
<span class="comment"> */</span>
<span class="literal">package</span> com.mycompany.lab6.exceptions_chloefontenot;
<span class="literal">import</span> java.io.File;
<span class="literal">import</span> java.util.ArrayList;
<span class="literal">import</span> java.util.Scanner;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST1">@author</span> <span class="comment">chloe</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> ProcessScoresInTextFile {
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST2">main</span>(String[] args) <span class="literal">throws</span> Exception
{
File file = <span class="literal">new</span> File(<span class="string">&quot;</span><span class="string">scores.txt</span><span class="string">&quot;</span>);
<span class="comment">// Create a scanner for the file</span>
Scanner input = <span class="literal">new</span> Scanner(file);
ArrayList&lt;String&gt; nameAR = <span class="literal">new</span> ArrayList&lt;&gt;();
ArrayList&lt;Integer&gt; intAR = <span class="literal">new</span> ArrayList&lt;&gt;();
<span class="comment">// Read data from file</span>
<span class="literal">int</span> iterate = <span class="number">0</span>;
<span class="literal">int</span> score;
<span class="literal">while</span> (input.hasNext()) {
iterate++;
String name = input.next();
score = input.nextInt();
nameAR.add(name);
intAR.add((Integer) score);
}
<span class="literal">double</span> average = <span class="number">0</span>;
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i &lt; intAR.size(); ++i) {
System.<span class="ST3">out</span>.print(nameAR.get(i) + <span class="string">&quot;</span> <span class="string">&quot;</span>);
System.<span class="ST3">out</span>.println(intAR.get(i));
average += intAR.get(i);
}
average = (average / intAR.size());
System.<span class="ST3">out</span>.println(<span class="string">&quot;</span><span class="string">Average: </span><span class="string">&quot;</span> + average);
}
}
</pre></body>
</html>

View File

@@ -0,0 +1,73 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>ReadFileFromURL.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}
.string {color: #6a8759}
.number {color: #6897bb}
.comment {color: #808080}
.whitespace {color: #505050}
.ST2 {color: #ffc66d; font-family: monospace; font-style: italic}
.ST3 {color: #9876aa; font-family: monospace; font-style: italic}
.ST1 {color: #808080; font-family: monospace; font-weight: bold}
.ST0 {color: #287bde}
.literal {color: #cc7832}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/chloe/ASDV-Java/Semester 2/Assignments/lab6-Exceptions_ChloeFontenot/src/main/java/com/mycompany/lab6/exceptions_chloefontenot/ReadFileFromURL.java</td></tr></table>
<pre>
<span class="comment">/*</span>
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
<span class="comment"> */</span>
<span class="literal">package</span> com.mycompany.lab6.exceptions_chloefontenot;
<span class="literal">import</span> java.util.Scanner;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST1">@author</span> <span class="comment">chloe</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> ReadFileFromURL {
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST2">main</span>(String[] args)
{
<span class="literal">boolean</span> continueLoop = <span class="literal">false</span>;
<span class="literal">boolean</span> exceptionThrown = <span class="literal">false</span>;
<span class="literal">do</span> {
System.<span class="ST3">out</span>.print(<span class="string">&quot;</span><span class="string">Enter a URL: </span><span class="string">&quot;</span>);
String URLString = <span class="literal">new</span> Scanner(System.<span class="ST3">in</span>).next();
<span class="literal">try</span> {
java.net.URL url = <span class="literal">new</span> java.net.URL(URLString);
<span class="literal">int</span> count = <span class="number">0</span>;
Scanner input = <span class="literal">new</span> Scanner(url.openStream());
<span class="literal">while</span> (input.hasNext()) {
String line = input.nextLine();
count += line.length();
}
System.<span class="ST3">out</span>.println(<span class="string">&quot;</span><span class="string">The file size is </span><span class="string">&quot;</span> + count + <span class="string">&quot;</span><span class="string"> characters</span><span class="string">&quot;</span>);
exceptionThrown = <span class="literal">false</span>;
} <span class="literal">catch</span> (java.net.MalformedURLException ex) {
System.<span class="ST3">out</span>.println(<span class="string">&quot;</span><span class="string">Invalid URL</span><span class="string">&quot;</span>);
exceptionThrown = <span class="literal">true</span>;
} <span class="literal">catch</span> (java.io.IOException ex) {
System.<span class="ST3">out</span>.println(<span class="string">&quot;</span><span class="string">IO Errors</span><span class="string">&quot;</span>);
}
<span class="literal">if</span> (exceptionThrown) {
continueLoop = <span class="literal">true</span>;
} <span class="literal">else</span> {
continueLoop = <span class="literal">false</span>;
}
} <span class="literal">while</span> (continueLoop);
}
}
</pre></body>
</html>

View File

@@ -0,0 +1,61 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>ReadFileFromWeb.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}
.string {color: #6a8759}
.number {color: #6897bb}
.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/chloe/ASDV-Java/Semester 2/Assignments/lab6-Exceptions_ChloeFontenot/src/main/java/com/mycompany/lab6/exceptions_chloefontenot/ReadFileFromWeb.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_chloefontenot;
<span class="literal">import</span> java.util.Scanner;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST0">@author</span> <span class="comment">chloe</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> ReadFileFromWeb {
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args) {
System.out.print(<span class="string">&quot;</span><span class="string">Enter a URL: </span><span class="string">&quot;</span>);
String URLString = <span class="literal">new</span> Scanner(System.in).next();
<span class="literal">try</span> {
java.net.URL url = <span class="literal">new</span> java.net.URL(URLString);
<span class="literal">int</span> count = <span class="number">0</span>;
String text =<span class="string">&quot;&quot;</span>;
Scanner input = <span class="literal">new</span> Scanner(url.openStream());
<span class="literal">while</span> (input.hasNext()) {
String line = input.nextLine();
count += line.length();
text += line;
}
System.out.println(<span class="string">&quot;</span><span class="string">The file size is </span><span class="string">&quot;</span> + count + <span class="string">&quot;</span><span class="string"> characters.</span><span class="string">&quot;</span>);
System.out.println(text);
} <span class="literal">catch</span> (java.net.MalformedURLException ex) {
System.out.println(<span class="string">&quot;</span><span class="string">Invalid URL</span><span class="string">&quot;</span>);
}
<span class="literal">catch</span> (java.io.IOException ex) {
System.out.println(<span class="string">&quot;</span><span class="string">IO Errors!</span><span class="string">&quot;</span>);
}
}
}
</pre></body>
</html>

View File

@@ -0,0 +1,80 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>ReadFileFromWeb1.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}
.string {color: #6a8759}
.number {color: #6897bb}
.comment {color: #808080}
.whitespace {color: #505050}
.ST2 {color: #ffc66d; font-family: monospace; font-style: italic}
.ST3 {color: #9876aa; font-family: monospace; font-style: italic}
.ST1 {color: #808080; font-family: monospace; font-weight: bold}
.ST0 {color: #287bde}
.literal {color: #cc7832}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/chloe/ASDV-Java/Semester 2/Assignments/lab6-Exceptions_ChloeFontenot/src/main/java/com/mycompany/lab6/exceptions_chloefontenot/ReadFileFromWeb1.java</td></tr></table>
<pre>
<span class="comment">/*</span>
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
<span class="comment"> */</span>
<span class="literal">package</span> com.mycompany.lab6.exceptions_chloefontenot;
<span class="literal">import</span> java.util.Scanner;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST1">@author</span> <span class="comment">chloe</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> ReadFileFromWeb1 {
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST2">main</span>(String[] args) {
System.<span class="ST3">out</span>.print(<span class="string">&quot;</span><span class="string">Enter a URL (defaults to </span><span class="literal">\&quot;</span><span class="ST0">https://chloefontenot.com</span><span class="ST0">\</span><span class="literal">&quot;</span><span class="string">): </span><span class="string">&quot;</span>);
String URLinput = <span class="literal">new</span> Scanner(System.<span class="ST3">in</span>).nextLine();
String URLString;
<span class="literal">if</span> (URLinput.isEmpty()) {
URLString = <span class="string">&quot;</span><span class="ST0">https://chloefontenot.com</span><span class="string">&quot;</span>;
}
<span class="literal">else</span> {
URLString = URLinput;
}
<span class="literal">try</span> {
java.net.URL url = <span class="literal">new</span> java.net.URL(URLString);
<span class="literal">int</span> count = <span class="number">0</span>, divCount = <span class="number">0</span>, pCount = <span class="number">0</span>;
String text =<span class="string">&quot;&quot;</span>;
Scanner input = <span class="literal">new</span> Scanner(url.openStream());
<span class="literal">while</span> (input.hasNext()) {
String line = input.nextLine();
count += line.length();
text += line;
<span class="literal">if</span> (line.contains(<span class="string">&quot;</span><span class="string">&lt;div</span><span class="string">&quot;</span>)) {
divCount++;
}
<span class="literal">if</span> (line.contains(<span class="string">&quot;</span><span class="string">&lt;p</span><span class="string">&quot;</span>)) {
pCount++;
}
}
System.<span class="ST3">out</span>.println(<span class="string">&quot;</span><span class="string">The file size is </span><span class="string">&quot;</span> + count + <span class="string">&quot;</span><span class="string"> characters.</span><span class="string">&quot;</span>);
System.<span class="ST3">out</span>.println(<span class="string">&quot;</span><span class="string">There are </span><span class="string">&quot;</span> + divCount + <span class="string">&quot;</span><span class="string"> &lt;div&gt; tags on this site.</span><span class="string">&quot;</span>);
System.<span class="ST3">out</span>.println(<span class="string">&quot;</span><span class="string">There are </span><span class="string">&quot;</span> + pCount + <span class="string">&quot;</span><span class="string"> &lt;p&gt; tags on this site.</span><span class="string">&quot;</span>);
System.<span class="ST3">out</span>.println(text);
} <span class="literal">catch</span> (java.net.MalformedURLException ex) {
System.<span class="ST3">out</span>.println(<span class="string">&quot;</span><span class="string">Invalid URL</span><span class="string">&quot;</span>);
}
<span class="literal">catch</span> (java.io.IOException ex) {
System.<span class="ST3">out</span>.println(<span class="string">&quot;</span><span class="string">IO Errors!</span><span class="string">&quot;</span>);
}
}
}
</pre></body>
</html>

View File

@@ -0,0 +1,57 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>TestFileClass.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}
.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/chloe/ASDV-Java/Semester 2/Assignments/lab6-Exceptions_ChloeFontenot/src/main/java/com/mycompany/lab6/exceptions_chloefontenot/TestFileClass.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_chloefontenot;
<span class="literal">import</span> java.util.Scanner;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST0">@author</span> <span class="comment">chloe</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> TestFileClass {
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args) {
Scanner input = <span class="literal">new</span> Scanner(System.in);
System.out.print(<span class="string">&quot;</span><span class="string">Enter a file path or directory: </span><span class="string">&quot;</span>);
String filePath = input.nextLine();
testFile(filePath);
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> testFile(String filePath) {
java.io.File file = <span class="literal">new</span> java.io.File(filePath);
System.out.println(<span class="string">&quot;</span><span class="string">Does it exist? </span><span class="string">&quot;</span> + file.exists());
System.out.println(<span class="string">&quot;</span><span class="string">The file has </span><span class="string">&quot;</span> + file.length() + <span class="string">&quot;</span><span class="string"> bytes.</span><span class="string">&quot;</span>);
System.out.println(<span class="string">&quot;</span><span class="string">Can it be read? </span><span class="string">&quot;</span> + file.canRead());
System.out.println(<span class="string">&quot;</span><span class="string">Can it be written? </span><span class="string">&quot;</span> + file.canWrite());
System.out.println(<span class="string">&quot;</span><span class="string">Is it a directory? </span><span class="string">&quot;</span> + file.isDirectory());
System.out.println(<span class="string">&quot;</span><span class="string">Is it a file? </span><span class="string">&quot;</span> + file.isFile());
System.out.println(<span class="string">&quot;</span><span class="string">Is it absolute? </span><span class="string">&quot;</span> + file.isAbsolute());
System.out.println(<span class="string">&quot;</span><span class="string">Is it hidden? </span><span class="string">&quot;</span> + file.isHidden());
System.out.println(<span class="string">&quot;</span><span class="string">The absolute path to this file is </span><span class="string">&quot;</span> + file.getAbsolutePath());
System.out.println(<span class="string">&quot;</span><span class="string">Last modified on </span><span class="string">&quot;</span> + <span class="literal">new</span> java.util.Date(file.lastModified()));
}
}
</pre></body>
</html>

View File

@@ -0,0 +1,68 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>ToDecimal.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/chloe/ASDV-Java/Semester 2/Assignments/lab6-Exceptions_ChloeFontenot/src/main/java/com/mycompany/lab6/exceptions_chloefontenot/ToDecimal.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_chloefontenot;
<span class="literal">import</span> java.util.Scanner;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST0">@author</span> <span class="comment">chloe</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> ToDecimal {
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">int</span> hexToDecimal(String hex) {
<span class="literal">int</span> decimalValue =<span class="number">0</span>;
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i &lt; hex.length(); ++i) {
<span class="literal">char</span> hexChar = hex.charAt(i);
decimalValue = decimalValue * <span class="number">16</span> + hexCharToDecimal(hexChar);
}
<span class="literal">return</span> decimalValue;
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">int</span> hexCharToDecimal(<span class="literal">char</span> ch) {
ch = Character.toUpperCase(ch);
<span class="literal">if</span> (ch &gt;= <span class="string">&#39;</span><span class="string">A</span><span class="string">&#39;</span> &amp;&amp; ch &lt;= <span class="string">&#39;</span><span class="string">F</span><span class="string">&#39;</span>) {
<span class="literal">return</span> <span class="number">10</span> + ch - <span class="string">&#39;</span><span class="string">A</span><span class="string">&#39;</span>;
} <span class="literal">else</span> <span class="literal">if</span> (ch &gt;= <span class="string">&#39;</span><span class="string">0</span><span class="string">&#39;</span> &amp;&amp; ch &lt;= <span class="string">&#39;</span><span class="string">9</span><span class="string">&#39;</span>){ <span class="comment">// ch is &#39;0&#39;, &#39;1&#39;, or &#39;9&#39;</span>
<span class="literal">return</span> ch - <span class="string">&#39;</span><span class="string">0</span><span class="string">&#39;</span>;
} <span class="literal">else</span> {
<span class="literal">throw</span> <span class="literal">new</span> NumberFormatException(<span class="string">&quot;</span><span class="string">Invalid hex character</span><span class="string">&quot;</span>);
}
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args) {
Scanner input = <span class="literal">new</span> Scanner(System.in);
System.out.print(<span class="string">&quot;</span><span class="string">Enter a hex number or q/Q to quit: </span><span class="string">&quot;</span>);
String hex = input.nextLine();
<span class="literal">while</span> (<span class="string">&quot;</span><span class="string">q</span><span class="string">&quot;</span>.equals(hex.toLowerCase()) == <span class="literal">false</span>) {
System.out.println(<span class="string">&quot;</span><span class="string">The decimal value for hex number </span><span class="string">&quot;</span> + hex + <span class="string">&quot;</span><span class="string"> is </span><span class="string">&quot;</span> + hexToDecimal(hex.toUpperCase()));
System.out.print(<span class="string">&quot;</span><span class="string">Emter a hex number: </span><span class="string">&quot;</span>);
hex = input.nextLine();
}
}
}
</pre></body>
</html>

View File

@@ -0,0 +1,75 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Triangle.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/chloe/ASDV-Java/Semester 2/Assignments/lab6-Exceptions_ChloeFontenot/src/main/java/com/mycompany/lab6/exceptions_chloefontenot/Triangle.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_chloefontenot;
<span class="literal">import</span> java.util.Scanner;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST0">@author</span> <span class="comment">chloe</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> Triangle <span class="literal">implements</span> Geo{
<span class="literal">private</span> <span class="literal">double</span> side1 = <span class="number">1.0</span>, side2 = <span class="number">1.0</span>, side3 = <span class="number">1.0</span>;
<span class="literal">public</span> Triangle(<span class="literal">double</span> side1, <span class="literal">double</span> side2, <span class="literal">double</span> side3) {
<span class="literal">this</span>.side1 = side1;
<span class="literal">this</span>.side2 = side2;
<span class="literal">this</span>.side3 = side3;
}
@Override
<span class="literal">public</span> <span class="literal">double</span> getArea() {
<span class="literal">double</span> s = (side1 + side2 + side3) / <span class="number">2</span>;
<span class="literal">return</span> Math.sqrt(s * (s - side1) * (s - side2) * (s - side3));
}
@Override
<span class="literal">public</span> <span class="literal">double</span> getPerimeter() {
<span class="literal">return</span> side1 + side2 + side3;
}
@Override
<span class="literal">public</span> String toString() {
<span class="literal">return</span> <span class="string">&quot;</span><span class="string">Triangle: side1 = </span><span class="string">&quot;</span> + side1 + <span class="string">&quot;</span><span class="string"> side2 = </span><span class="string">&quot;</span> + side2 + <span class="string">&quot;</span><span class="string"> side3 = </span><span class="string">&quot;</span> + side3;
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args) {
Scanner input = <span class="literal">new</span> Scanner(System.in);
System.out.println(<span class="string">&quot;</span><span class="string">Enter the three sides: </span><span class="string">&quot;</span>);
<span class="literal">double</span> side1 = input.nextDouble();
<span class="literal">double</span> side2 = input.nextDouble();
<span class="literal">double</span> side3 = input.nextDouble();
Triangle triangle = <span class="literal">new</span> Triangle(side1, side2, side3);
System.out.println(<span class="string">&quot;</span><span class="string">The area is </span><span class="string">&quot;</span> + triangle.getArea());
System.out.println(<span class="string">&quot;</span><span class="string">The perimeter is </span><span class="string">&quot;</span> + triangle.getPerimeter());
System.out.println(triangle);
}
}
<span class="literal">interface</span> Geo {
<span class="literal">double</span> getArea();
<span class="literal">public</span> <span class="literal">double</span> getPerimeter();
}
</pre></body>
</html>

View File

@@ -0,0 +1,66 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>WriteReadData.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}
.string {color: #6a8759}
.number {color: #6897bb}
.comment {color: #808080}
.whitespace {color: #505050}
.ST2 {color: #ffc66d; font-family: monospace; font-style: italic}
.ST3 {color: #9876aa; font-family: monospace; font-style: italic}
.ST1 {color: #808080; font-family: monospace; font-weight: bold}
.ST0 {color: #287bde}
.literal {color: #cc7832}
.ST4 {font-family: monospace; font-style: italic}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/chloe/ASDV-Java/Semester 2/Assignments/lab6-Exceptions_ChloeFontenot/src/main/java/com/mycompany/lab6/exceptions_chloefontenot/WriteReadData.java</td></tr></table>
<pre>
<span class="comment">/*</span>
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
<span class="comment"> */</span>
<span class="literal">package</span> com.mycompany.lab6.exceptions_chloefontenot;
<span class="literal">import</span> java.io.File;
<span class="literal">import</span> java.io.PrintWriter;
<span class="literal">import</span> java.util.Scanner;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST1">@author</span> <span class="comment">chloe</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> WriteReadData {
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST2">main</span>(String[] args) <span class="literal">throws</span> Exception
{
File file = <span class="literal">new</span> File(<span class="string">&quot;</span><span class="string">rw.txt</span><span class="string">&quot;</span>);
<span class="literal">int</span> randInt;
<span class="literal">if</span> (!file.exists()) {
System.<span class="ST3">out</span>.println(<span class="string">&quot;</span><span class="string">File does not exist! Creating it...</span><span class="string">&quot;</span>);
<span class="literal">try</span> (PrintWriter output = <span class="literal">new</span> PrintWriter(file);) {
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i &lt; <span class="number">100</span>; ++i) {
randInt = (<span class="literal">int</span>) (Math.<span class="ST4">random</span>() * <span class="number">100</span>);
System.<span class="ST3">out</span>.println(<span class="string">&quot;</span><span class="string">Writing </span><span class="string">&quot;</span> + randInt + <span class="string">&quot;</span><span class="string"> to file...</span><span class="string">&quot;</span>);
output.write(Integer.<span class="ST4">toString</span>(randInt) + <span class="string">&quot;</span><span class="literal">\n</span><span class="string">&quot;</span>);
}
} <span class="literal">catch</span> (Exception ex) {
System.<span class="ST3">out</span>.println(ex);
}
}
Scanner input = <span class="literal">new</span> Scanner(file);
System.<span class="ST3">out</span>.println(<span class="string">&quot;</span><span class="string">Reading file contents:</span><span class="string">&quot;</span>);
<span class="literal">while</span> (input.hasNext()) {
System.<span class="ST3">out</span>.println(input.next());
}
}
}
</pre></body>
</html>

View File

@@ -0,0 +1,61 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>WriteWithAutoClose.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}
.string {color: #6a8759}
.number {color: #6897bb}
.comment {color: #808080}
.whitespace {color: #505050}
.ST2 {color: #ffc66d; font-family: monospace; font-style: italic}
.ST3 {color: #9876aa; font-family: monospace; font-style: italic}
.ST1 {color: #808080; font-family: monospace; font-weight: bold}
.ST0 {color: #287bde}
.literal {color: #cc7832}
.ST4 {font-family: monospace; font-style: italic}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/chloe/ASDV-Java/Semester 2/Assignments/lab6-Exceptions_ChloeFontenot/src/main/java/com/mycompany/lab6/exceptions_chloefontenot/WriteWithAutoClose.java</td></tr></table>
<pre>
<span class="comment">/*</span>
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
<span class="comment"> */</span>
<span class="literal">package</span> com.mycompany.lab6.exceptions_chloefontenot;
<span class="literal">import</span> java.io.IOException;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST1">@author</span> <span class="comment">chloe</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> WriteWithAutoClose {
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST2">main</span>(String[] args) <span class="literal">throws</span> IOException
{
java.io.File file = <span class="literal">new</span> java.io.File(<span class="string">&quot;</span><span class="string">scores.txt</span><span class="string">&quot;</span>);
<span class="literal">if</span> (file.exists()) {
System.<span class="ST3">out</span>.println(<span class="string">&quot;</span><span class="string">File already exists!</span><span class="string">&quot;</span>);
System.<span class="ST4">exit</span>(<span class="number">0</span>);
}
<span class="comment">//throw new IOException(); //Just for testing :)</span>
<span class="literal">try</span> (java.io.PrintWriter output = <span class="literal">new</span> java.io.PrintWriter(file);) {
<span class="comment">// Write formatted output to the file</span>
output.print(<span class="string">&quot;</span><span class="string">John T Smith </span><span class="string">&quot;</span>);
output.println(<span class="number">9</span><span class="number">0</span>);
output.print(<span class="string">&quot;</span><span class="string">Eric K Jones </span><span class="string">&quot;</span>);
output.println(<span class="number">8</span><span class="number">5</span>);
}
}
}
</pre></body>
</html>

View File

@@ -0,0 +1,63 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>WriteWithAutoClose2.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}
.string {color: #6a8759}
.number {color: #6897bb}
.comment {color: #808080}
.whitespace {color: #505050}
.ST2 {color: #ffc66d; font-family: monospace; font-style: italic}
.ST3 {color: #9876aa; font-family: monospace; font-style: italic}
.ST1 {color: #808080; font-family: monospace; font-weight: bold}
.ST0 {color: #287bde}
.literal {color: #cc7832}
.ST4 {font-family: monospace; font-style: italic}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/chloe/ASDV-Java/Semester 2/Assignments/lab6-Exceptions_ChloeFontenot/src/main/java/com/mycompany/lab6/exceptions_chloefontenot/WriteWithAutoClose2.java</td></tr></table>
<pre>
<span class="comment">/*</span>
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
<span class="comment"> */</span>
<span class="literal">package</span> com.mycompany.lab6.exceptions_chloefontenot;
<span class="comment">import</span> <span class="comment">java</span><span class="comment">.</span><span class="comment">io</span><span class="comment">.</span><span class="comment">IOException</span><span class="comment">;</span>
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST1">@author</span> <span class="comment">chloe</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> WriteWithAutoClose2 {
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST2">main</span>(String[] args) {
<span class="literal">try</span> {
java.io.File file = <span class="literal">new</span> java.io.File(<span class="string">&quot;</span><span class="string">scores.txt</span><span class="string">&quot;</span>);
<span class="literal">if</span> (file.exists()) {
System.<span class="ST3">out</span>.println(<span class="string">&quot;</span><span class="string">File already exists!</span><span class="string">&quot;</span>);
System.<span class="ST4">exit</span>(<span class="number">0</span>);
}
<span class="comment">//throw new IOException(); //Just for testing :)</span>
<span class="literal">try</span> (java.io.PrintWriter output = <span class="literal">new</span> java.io.PrintWriter(file);) {
<span class="comment">// Write formatted output to the file</span>
output.print(<span class="string">&quot;</span><span class="string">John T Smith </span><span class="string">&quot;</span>);
output.println(<span class="number">9</span><span class="number">0</span>);
output.print(<span class="string">&quot;</span><span class="string">Eric K Jones </span><span class="string">&quot;</span>);
output.println(<span class="number">8</span><span class="number">5</span>);
}
} <span class="literal">catch</span> (Exception ex) {
System.<span class="ST3">err</span>.println(<span class="string">&quot;</span><span class="string">Cought exception: </span><span class="string">&quot;</span> + ex);
}
}
}
</pre></body>
</html>

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
<!--
Properties that influence various parts of the IDE, especially code formatting and the like.
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<org-netbeans-modules-javascript2-requirejs.enabled>true</org-netbeans-modules-javascript2-requirejs.enabled>
</properties>
</project-shared-configuration>

View File

@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<actions>
<action>
<actionName>run</actionName>
<packagings>
<packaging>jar</packaging>
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:3.0.0:exec</goal>
</goals>
<properties>
<exec.vmArgs>-enableassertions</exec.vmArgs>
<exec.args>${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs}</exec.args>
<exec.appArgs></exec.appArgs>
<exec.mainClass>${packageClassName}</exec.mainClass>
<exec.executable>java</exec.executable>
</properties>
</action>
<action>
<actionName>debug</actionName>
<packagings>
<packaging>jar</packaging>
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:3.0.0:exec</goal>
</goals>
<properties>
<exec.vmArgs>-enableassertions -agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address}</exec.vmArgs>
<exec.args>${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs}</exec.args>
<exec.appArgs></exec.appArgs>
<exec.mainClass>${packageClassName}</exec.mainClass>
<exec.executable>java</exec.executable>
<jpda.listen>true</jpda.listen>
</properties>
</action>
<action>
<actionName>profile</actionName>
<packagings>
<packaging>jar</packaging>
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:3.0.0:exec</goal>
</goals>
<properties>
<exec.vmArgs>-enableassertions</exec.vmArgs>
<exec.args>${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs}</exec.args>
<exec.mainClass>${packageClassName}</exec.mainClass>
<exec.executable>java</exec.executable>
<exec.appArgs></exec.appArgs>
</properties>
</action>
</actions>

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_ChloeFontenot</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_chloefontenot.Lab6Exceptions_ChloeFontenot</exec.mainClass>
</properties>
</project>

View File

@@ -0,0 +1,100 @@
66
31
93
98
45
64
73
43
97
21
98
20
18
87
91
43
30
71
15
14
53
4
81
18
76
22
88
89
76
51
94
56
64
72
96
87
43
66
61
46
46
44
32
26
90
97
97
75
97
11
95
55
9
95
17
52
19
64
31
66
62
15
77
28
73
55
34
51
72
51
88
14
98
45
0
97
66
78
94
95
5
54
92
63
69
72
91
94
43
79
56
75
54
26
37
49
77
40
6
28

View File

@@ -0,0 +1,4 @@
Chloe 90
Hailey 85
Davin 100
Tyler 95

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_chloefontenot;
/**
*
* @author chloefontenot
*/
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,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_chloefontenot;
/**
*
* @author chloefontenot
*/
public class CircleWithUncheckedException {
private double radius;
public CircleWithUncheckedException()
{
this(1.0);
}
public CircleWithUncheckedException(double radius)
{
if (radius < 0) {
throw new IllegalArgumentException("Radius cannot be negative.");
}
this.radius = radius;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
if (radius < 0) {
throw new IllegalArgumentException("Radius cannot be negative.");
}
this.radius = radius;
}
@Override
public String toString() {
return "CircleWithUnheckedException{" + "radius=" + radius + '}';
}
public static void main(String[] args) {
try {
System.out.println(new CircleWithUncheckedException(5));
System.out.println(new CircleWithUncheckedException(-5));
System.out.println(new CircleWithUncheckedException(10));
} catch (Exception ex) {
System.err.println(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_chloefontenot;
/**
*
* @author chloefontenot
*/
public class Lab6Exceptions_ChloeFontenot {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}

View File

@@ -0,0 +1,45 @@
/*
* 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_chloefontenot;
import java.io.File;
import java.util.ArrayList;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class ProcessScoresInTextFile {
public static void main(String[] args) throws Exception
{
File file = new File("scores.txt");
// Create a scanner for the file
Scanner input = new Scanner(file);
ArrayList<String> nameAR = new ArrayList<>();
ArrayList<Integer> intAR = new ArrayList<>();
// Read data from file
int iterate = 0;
int score;
while (input.hasNext()) {
iterate++;
String name = input.next();
score = input.nextInt();
nameAR.add(name);
intAR.add((Integer) score);
}
double average = 0;
for (int i = 0; i < intAR.size(); ++i) {
System.out.print(nameAR.get(i) + " ");
System.out.println(intAR.get(i));
average += intAR.get(i);
}
average = (average / intAR.size());
System.out.println("Average: " + average);
}
}

View File

@@ -0,0 +1,45 @@
/*
* 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_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class ReadFileFromURL {
public static void main(String[] args)
{
boolean continueLoop = false;
boolean exceptionThrown = false;
do {
System.out.print("Enter a URL: ");
String URLString = new Scanner(System.in).next();
try {
java.net.URL url = new java.net.URL(URLString);
int count = 0;
Scanner input = new Scanner(url.openStream());
while (input.hasNext()) {
String line = input.nextLine();
count += line.length();
}
System.out.println("The file size is " + count + " characters");
exceptionThrown = false;
} catch (java.net.MalformedURLException ex) {
System.out.println("Invalid URL");
exceptionThrown = true;
} catch (java.io.IOException ex) {
System.out.println("IO Errors");
}
if (exceptionThrown) {
continueLoop = true;
} else {
continueLoop = false;
}
} while (continueLoop);
}
}

View File

@@ -0,0 +1,36 @@
/*
* 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_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class ReadFileFromWeb {
public static void main(String[] args) {
System.out.print("Enter a URL: ");
String URLString = new Scanner(System.in).next();
try {
java.net.URL url = new java.net.URL(URLString);
int count = 0;
String text ="";
Scanner input = new Scanner(url.openStream());
while (input.hasNext()) {
String line = input.nextLine();
count += line.length();
text += line;
}
System.out.println("The file size is " + count + " characters.");
System.out.println(text);
} catch (java.net.MalformedURLException ex) {
System.out.println("Invalid URL");
}
catch (java.io.IOException ex) {
System.out.println("IO Errors!");
}
}
}

View File

@@ -0,0 +1,55 @@
/*
* 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_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class ReadFileFromWeb1 {
public static void main(String[] args)
{
System.out.print("Enter a URL (defaults to \"https://chloefontenot.com\"): ");
String URLinput;
String URLString;
try {
URLinput = new Scanner(System.in).nextLine();
//URLinput = "";
if (URLinput.isEmpty()) {
URLString = "https://chloefontenot.com";
} else {
URLString = URLinput;
}
java.net.URL url = new java.net.URL(URLString);
int count = 0, divCount = 0, pCount = 0;
String text = "";
Scanner input = new Scanner(url.openStream());
while (input.hasNext()) {
String line = input.nextLine();
count += line.length();
text += line;
if (line.contains("<div")) {
divCount++;
}
if (line.contains("<p")) {
pCount++;
}
}
System.out.println("The file size is " + count + " characters.");
System.out.println("There are " + divCount + " <div> tags on this site.");
System.out.println("There are " + pCount + " <p> tags on this site.");
System.out.println(text);
} catch (java.net.MalformedURLException ex) {
System.out.println("Invalid URL");
} catch (java.io.IOException ex) {
System.out.println("IO Errors!");
}
}
}

View File

@@ -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.mycompany.lab6.exceptions_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class TestFileClass {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a file path or directory: ");
String filePath = input.nextLine();
testFile(filePath);
}
public static void testFile(String filePath) {
java.io.File file = new java.io.File(filePath);
System.out.println("Does it exist? " + file.exists());
System.out.println("The file has " + file.length() + " bytes.");
System.out.println("Can it be read? " + file.canRead());
System.out.println("Can it be written? " + file.canWrite());
System.out.println("Is it a directory? " + file.isDirectory());
System.out.println("Is it a file? " + file.isFile());
System.out.println("Is it absolute? " + file.isAbsolute());
System.out.println("Is it hidden? " + file.isHidden());
System.out.println("The absolute path to this file is " + file.getAbsolutePath());
System.out.println("Last modified on " + new java.util.Date(file.lastModified()));
}
}

View File

@@ -0,0 +1,88 @@
/*
* 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_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class ToDecimal {
public static int hexToDecimal(String hex)
{
int decimalValue = 0;
for (int i = 0; i < hex.length(); ++i) {
char hexChar = hex.charAt(i);
decimalValue = decimalValue * 16 + hexCharToDecimal(hexChar);
}
return decimalValue;
}
public static int hexCharToDecimal(char ch)
{
ch = Character.toUpperCase(ch);
if (ch >= 'A' && ch <= 'F') {
return 10 + ch - 'A';
} else if (ch >= '0' && ch <= '9') { // ch is '0', '1', or '9'
return ch - '0';
} else {
throw new NumberFormatException("Invalid hex character");
}
}
/**
*
* @param binaryString the binary number to convert to decimal
* @return decimal number
* @throws NumberFormatException
* @throws NullPointerException
*/
public static int binToDecimal(String binaryString) throws NumberFormatException, NullPointerException
{
int returnInt = 0, binary = 1;
// Validate number first
if (binaryString == null) {
throw new NullPointerException("string is null");
}
for (int i = 0; i < binaryString.length() - 1; ++i) {
if (binaryString.charAt(i) != '0' && binaryString.charAt(i) != '1') {
throw new NumberFormatException(binaryString + " is not a binary number!");
}
}
binaryString = binaryString.trim();
for (int i = binaryString.length() - 1; i >= 0; --i) {
//System.out.println("bin" + binaryString.charAt(i));
if (binaryString.charAt(i) == '1') {
//System.out.println("Adding " + binary);
returnInt += binary;
}
binary *= 2;
//System.out.println(binary);
}
return returnInt;
}
public static void main(String[] args)
{
try {
binToDecimal("Jeff Bezos");
} catch (NumberFormatException ex) {
System.out.println(ex);
System.out.println("Binary number validation works!");
}
System.out.println(binToDecimal("1010"));
Scanner input = new Scanner(System.in);
System.out.print("Enter a hex number or q/Q to quit: ");
String hex = input.nextLine();
while ("q".equals(hex.toLowerCase()) == false) {
System.out.println("The decimal value for hex number " + hex + " is " + hexToDecimal(hex.toUpperCase()));
System.out.print("Enter a hex number: ");
hex = input.nextLine();
}
}
}

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_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class Triangle implements Geo{
private double side1 = 1.0, side2 = 1.0, side3 = 1.0;
public Triangle(double side1, double side2, double side3) {
this.side1 = side1;
this.side2 = side2;
this.side3 = side3;
}
@Override
public double getArea() {
double s = (side1 + side2 + side3) / 2;
return Math.sqrt(s * (s - side1) * (s - side2) * (s - side3));
}
@Override
public double getPerimeter() {
return side1 + side2 + side3;
}
@Override
public String toString() {
return "Triangle: side1 = " + side1 + " side2 = " + side2 + " side3 = " + side3;
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter the three sides: ");
double side1 = input.nextDouble();
double side2 = input.nextDouble();
double side3 = input.nextDouble();
Triangle triangle = new Triangle(side1, side2, side3);
System.out.println("The area is " + triangle.getArea());
System.out.println("The perimeter is " + triangle.getPerimeter());
System.out.println(triangle);
}
}
interface Geo {
double getArea();
public double getPerimeter();
}

View File

@@ -0,0 +1,38 @@
/*
* 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_chloefontenot;
import java.io.File;
import java.io.PrintWriter;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class WriteReadData {
public static void main(String[] args) throws Exception
{
File file = new File("rw.txt");
int randInt;
if (!file.exists()) {
System.out.println("File does not exist! Creating it...");
try (PrintWriter output = new PrintWriter(file);) {
for (int i = 0; i < 100; ++i) {
randInt = (int) (Math.random() * 100);
System.out.println("Writing " + randInt + " to file...");
output.write(Integer.toString(randInt) + "\n");
}
} catch (Exception ex) {
System.out.println(ex);
}
}
Scanner input = new Scanner(file);
System.out.println("Reading file contents:");
while (input.hasNext()) {
System.out.println(input.next());
}
}
}

View File

@@ -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.mycompany.lab6.exceptions_chloefontenot;
import java.io.IOException;
/**
*
* @author chloe
*/
public class WriteWithAutoClose {
public static void main(String[] args) throws IOException
{
java.io.File file = new java.io.File("scores.txt");
if (file.exists()) {
System.out.println("File already exists!");
System.exit(0);
}
//throw new IOException(); //Just for testing :)
try (java.io.PrintWriter output = new java.io.PrintWriter(file);) {
// Write formatted output to the file
output.print("John T Smith ");
output.println(90);
output.print("Eric K Jones ");
output.println(85);
}
}
}

View File

@@ -0,0 +1,34 @@
/*
* 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_chloefontenot;
import java.io.IOException;
/**
*
* @author chloe
*/
public class WriteWithAutoClose2 {
public static void main(String[] args) {
try {
java.io.File file = new java.io.File("scores.txt");
if (file.exists()) {
System.out.println("File already exists!");
System.exit(0);
}
//throw new IOException(); //Just for testing :)
try (java.io.PrintWriter output = new java.io.PrintWriter(file);) {
// Write formatted output to the file
output.print("John T Smith ");
output.println(90);
output.print("Eric K Jones ");
output.println(85);
}
} catch (Exception ex) {
System.err.println("Cought exception: " + ex);
}
}
}