ASDV-Java/Semester 2/Exams/Exam2-Practice1_CalebFontenot/Printed HTMLs/CountryOfOrigin.html
2023-08-14 11:41:26 -05:00

134 lines
8.4 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>CountryOfOrigin.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}
.ST2 {color: #9876aa}
.ST3 {color: #ffc66d}
.string {color: #6a8759}
.number {color: #6897bb}
.comment {color: #808080}
.whitespace {color: #505050}
.ST5 {color: #ffc66d; font-family: monospace; font-style: italic}
.ST6 {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/caleb/ASDV-Java/Semester 2/Exams/Exam2-Practice_CalebFontenot/src/main/java/com/calebfontenot/exam2/practice_calebfontenot/CountryOfOrigin.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.calebfontenot.exam2.practice_calebfontenot;
<span class="literal">import</span> java.util.Arrays;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST1">@author</span> <span class="comment">caleb</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> CountryOfOrigin <span class="literal">implements</span> Cloneable, Comparable&lt;CountryOfOrigin&gt; {
<span class="literal">private</span> <span class="literal">char</span>[] <span class="ST2">country</span> = <span class="string">&quot;</span><span class="string">USA</span><span class="string">&quot;</span>.toCharArray();
<span class="literal">public</span> CountryOfOrigin() {}
<span class="literal">public</span> CountryOfOrigin(<span class="literal">char</span>[] country)
{
<span class="literal">this</span>.<span class="ST2">country</span> = country;
}
<span class="literal">public</span> String <span class="ST3">getCountry</span>()
{
<span class="literal">return</span> String.<span class="ST4">copyValueOf</span>(<span class="literal">t</span><span class="literal">his</span>.<span class="ST2">country</span>);
}
<span class="literal">public</span> <span class="literal">void</span> <span class="ST3">setCountry</span>(<span class="literal">char</span>[] country)
{
<span class="literal">this</span>.<span class="ST2">country</span> = country;
}
<span class="literal">public</span> <span class="literal">boolean</span> <span class="ST3">changeOneLetter</span>(<span class="literal">int</span> index, <span class="literal">char</span> newLetter)
{
<span class="literal">if</span> (index &gt;= <span class="literal">this</span>.<span class="ST2">country</span>.<span class="ST2">length</span> || index &lt; <span class="number">0</span>) {
<span class="literal">return</span> <span class="literal">false</span>;
}
<span class="literal">this</span>.<span class="ST2">country</span>[index] = newLetter;
<span class="literal">return</span> <span class="literal">true</span>;
}
@Override
<span class="literal">public</span> <span class="literal">boolean</span> <span class="ST3">equals</span>(Object obj)
{
<span class="literal">if</span> (<span class="literal">this</span> == obj) {
<span class="literal">return</span> <span class="literal">true</span>;
}
<span class="literal">if</span> (obj == <span class="literal">null</span>) {
<span class="literal">return</span> <span class="literal">false</span>;
}
<span class="literal">if</span> (getClass() != obj.getClass()) {
<span class="literal">return</span> <span class="literal">false</span>;
}
<span class="literal">final</span> CountryOfOrigin other = (CountryOfOrigin) obj;
<span class="literal">return</span> Arrays.<span class="ST4">equals</span>(<span class="literal">t</span><span class="literal">his</span>.<span class="ST2">country</span>, other.<span class="ST2">country</span>);
}
@Override
<span class="literal">public</span> String <span class="ST3">toString</span>()
{
<span class="literal">return</span> String.<span class="ST4">copyValueOf</span>(<span class="literal">t</span><span class="literal">his</span>.<span class="ST2">country</span>);
}
@Override
<span class="literal">public</span> <span class="literal">int</span> <span class="ST3">compareTo</span>(CountryOfOrigin o)
{
<span class="literal">return</span> String.<span class="ST4">copyValueOf</span>(<span class="literal">t</span><span class="literal">his</span>.<span class="ST2">country</span>).compareTo(String.<span class="ST4">copyValueOf</span>(o.<span class="ST2">country</span>));
}
@Override
<span class="literal">public</span> Object <span class="ST3">clone</span>() {
<span class="literal">return</span> <span class="literal">new</span> CountryOfOrigin(<span class="literal">n</span><span class="literal">ew</span> String(<span class="literal">t</span><span class="literal">his</span>.<span class="ST2">country</span>).toCharArray());
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST5">main</span>(String[] args) <span class="literal">throws</span> CloneNotSupportedException
{
CountryOfOrigin c1 = <span class="literal">new</span> CountryOfOrigin();
CountryOfOrigin c2 = <span class="literal">new</span> CountryOfOrigin(<span class="string">&quot;</span><span class="string">GERMANY</span><span class="string">&quot;</span>.toCharArray());
CountryOfOrigin c3 = (CountryOfOrigin) c2.clone();
System.<span class="ST6">out</span>.println(<span class="string">&quot;</span><span class="string">c1 is: </span><span class="string">&quot;</span> + c1);
System.<span class="ST6">out</span>.println(<span class="string">&quot;</span><span class="string">c2 is: </span><span class="string">&quot;</span> + c2);
System.<span class="ST6">out</span>.println(<span class="string">&quot;</span><span class="string">c3 cloned of c2 is: </span><span class="string">&quot;</span> + c3);
c3.changeOneLetter(<span class="number">0</span>, <span class="string">&#39;</span><span class="string">J</span><span class="string">&#39;</span>);
c3.changeOneLetter(<span class="number">1</span>, <span class="string">&#39;</span><span class="string">A</span><span class="string">&#39;</span>);
c3.changeOneLetter(<span class="number">2</span>, <span class="string">&#39;</span><span class="string">P</span><span class="string">&#39;</span>);
System.<span class="ST6">out</span>.println(<span class="string">&quot;</span><span class="string">c3 after changeOneLetter is: </span><span class="string">&quot;</span> + c3);
System.<span class="ST6">out</span>.println(<span class="string">&quot;</span><span class="string">if this displays GERMANY and not JAPMANY</span><span class="literal">\n</span><span class="string">your clone is deep: </span><span class="string">&quot;</span> + c2);
System.<span class="ST6">out</span>.println(c1.compareTo(c2));
System.<span class="ST6">out</span>.println(c1.compareTo(c3));
System.<span class="ST6">out</span>.println(c1.equals(c2));
System.<span class="ST6">out</span>.println(c1.equals(c3));
System.<span class="ST6">out</span>.println(c2.getCountry());
c2.setCountry(<span class="string">&quot;</span><span class="string">ITALY</span><span class="string">&quot;</span>.toCharArray());
System.<span class="ST6">out</span>.println(c2.getCountry());
System.<span class="ST6">out</span>.println(c1.getCountry());
}
}
</pre></body>
</html>