126 lines
9.2 KiB
HTML
126 lines
9.2 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
|
<html>
|
|
<head>
|
|
<title>Automobile.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}
|
|
.number {color: #6897bb}
|
|
.string {color: #6a8759}
|
|
.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/Assignments/Exam2-Practice2_CalebFontenot/src/main/java/com/calebfontenot/exam2/practice2_calebfontenot/Automobile.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.practice2_calebfontenot;
|
|
|
|
<span class="literal">import</span> java.util.Objects;
|
|
|
|
<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> Automobile <span class="literal">extends</span> Vehicle <span class="literal">implements</span> Cloneable{
|
|
|
|
<span class="literal">private</span> String <span class="ST2">make</span>;
|
|
|
|
<span class="literal">public</span> Automobile(String make)
|
|
{
|
|
<span class="literal">this</span>.<span class="ST2">make</span> = make;
|
|
}
|
|
<span class="literal">public</span> Automobile(String make, String vin)
|
|
{
|
|
<span class="literal">super</span>(vin);
|
|
<span class="literal">this</span>.<span class="ST2">make</span> = make;
|
|
}
|
|
<span class="literal">public</span> String <span class="ST3">getMake</span>() { <span class="literal">return</span> <span class="ST2">make</span>; }
|
|
<span class="literal">public</span> <span class="literal">void</span> <span class="ST3">setMake</span>(String make) { <span class="literal">this</span>.<span class="ST2">make</span> = make; }
|
|
@Override
|
|
<span class="literal">public</span> <span class="literal">int</span> <span class="ST3">compareTo</span>(Vehicle o)
|
|
{
|
|
<span class="literal">return</span> <span class="literal">this</span>.getVin().compareTo(o.getVin());
|
|
}
|
|
@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> Automobile other = (Automobile) obj;
|
|
<span class="literal">boolean</span> isSameObjectType = Objects.<span class="ST4">equals</span>(<span class="literal">t</span><span class="literal">his</span>.<span class="ST2">make</span>, other.<span class="ST2">make</span>);
|
|
<span class="literal">if</span> (isSameObjectType) {
|
|
<span class="literal">if</span> (<span class="literal">this</span>.<span class="ST2">make</span>.compareTo(other.<span class="ST2">make</span>) == <span class="number">0</span> && (<span class="literal">this</span>.getVin().compareTo(other.getVin()) == <span class="number">0</span>)) {
|
|
<span class="literal">return</span> <span class="literal">true</span>;
|
|
} <span class="literal">else</span> {
|
|
<span class="literal">return</span> <span class="literal">false</span>;
|
|
}
|
|
} <span class="literal">else</span> {
|
|
<span class="literal">return</span> <span class="literal">false</span>;
|
|
}
|
|
}
|
|
@Override
|
|
<span class="literal">protected</span> Object <span class="ST3">clone</span>() <span class="literal">throws</span> CloneNotSupportedException {
|
|
String make = <span class="literal">new</span> String(<span class="literal">t</span><span class="literal">his</span>.getMake());
|
|
String vim = <span class="literal">new</span> String(<span class="literal">t</span><span class="literal">his</span>.getVin());
|
|
Automobile clonedAuto = <span class="literal">new</span> Automobile(make, vim);
|
|
<span class="literal">return</span> clonedAuto;
|
|
}
|
|
|
|
@Override
|
|
<span class="literal">public</span> String <span class="ST3">toString</span>()
|
|
{
|
|
<span class="literal">return</span> <span class="literal">super</span>.toString() + <span class="string">"</span><span class="literal">\n</span><span class="string">"</span> + <span class="string">"</span><span class="string">Automobile{</span><span class="string">"</span> + <span class="string">"</span><span class="string">make=</span><span class="string">"</span> + <span class="ST2">make</span> + <span class="string">'</span><span class="string">}</span><span class="string">'</span>;
|
|
}
|
|
|
|
<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
|
|
{
|
|
Automobile johnsBeemer = <span class="literal">new</span> Automobile (<span class="string">"</span><span class="string">BMW</span><span class="string">"</span>, <span class="string">"</span><span class="string">vin1BMW</span><span class="string">"</span>);
|
|
Automobile marysBeemer = <span class="literal">new</span> Automobile (<span class="string">"</span><span class="string">BMW</span><span class="string">"</span>, <span class="string">"</span><span class="string">vin2BMW</span><span class="string">"</span>);
|
|
|
|
Automobile johnsClonedBeemer = (Automobile) johnsBeemer.clone();
|
|
|
|
System.<span class="ST6">out</span>.println(johnsBeemer + <span class="string">"</span><span class="literal">\n</span><span class="string">"</span>);
|
|
System.<span class="ST6">out</span>.println(marysBeemer + <span class="string">"</span><span class="literal">\n</span><span class="string">"</span>);
|
|
System.<span class="ST6">out</span>.println(johnsClonedBeemer + <span class="string">"</span><span class="literal">\n</span><span class="string">"</span>);
|
|
|
|
|
|
|
|
System.<span class="ST6">out</span>.println(<span class="string">"</span><span class="string">John</span><span class="literal">\'</span><span class="string">s beemer EQUALS Mary</span><span class="literal">\'</span><span class="string">s beemer --> </span><span class="string">"</span> + johnsBeemer.equals(marysBeemer));
|
|
System.<span class="ST6">out</span>.println(<span class="string">"</span><span class="string">John</span><span class="literal">\'</span><span class="string">s beemer EQUALS John</span><span class="literal">\'</span><span class="string">s beemer --> </span><span class="string">"</span> + johnsBeemer.equals(johnsClonedBeemer));
|
|
|
|
System.<span class="ST6">out</span>.println(<span class="string">"</span><span class="string">John</span><span class="literal">\'</span><span class="string">s beemer COMPARE_TO John</span><span class="literal">\'</span><span class="string">s cloned beemer --> </span><span class="string">"</span> + johnsBeemer.compareTo(johnsClonedBeemer));
|
|
System.<span class="ST6">out</span>.println(<span class="string">"</span><span class="string">John</span><span class="literal">\'</span><span class="string">s beemer COMPARE_TO Mary</span><span class="literal">\'</span><span class="string">s beemer --> </span><span class="string">"</span> +johnsBeemer.compareTo(marysBeemer));
|
|
|
|
System.<span class="ST6">out</span>.println(<span class="string">"</span><span class="string">John</span><span class="literal">\'</span><span class="string">s beemer EQUALS Airplane --> </span><span class="string">"</span> + johnsBeemer.equals(<span class="literal">new</span> Airplane()));
|
|
}
|
|
}
|
|
|
|
<span class="literal">class</span> Airplane {}
|
|
|
|
</pre></body>
|
|
</html>
|