This commit is contained in:
Chloe Fontenot 🏳️‍⚧️ 2023-04-11 14:12:21 -05:00
parent 466e438eee
commit a28a353b68
70 changed files with 1766 additions and 0 deletions

2
.gitignore vendored
View File

@ -117,3 +117,5 @@
/Semester 2/Assignments/lab6-Exceptions_CalebFontenot/target/
/Semester 2/Assignments/fileClassTest/target/
/Semester 2/Assignments/lab7_CalebFontenot/target/
/Semester 2/Assignments/lab8_CalebFontenot/target/
/Semester 2/Assignments/lab8_2_CalebFontenot/target/

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.calebfontenot</groupId>
<artifactId>AbstractMethod</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.calebfontenot.abstractmethod.AbstractMethod</exec.mainClass>
</properties>
</project>

View File

@ -0,0 +1,67 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
*/
package com.calebfontenot.abstractmethod;
/**
*
* @author caleb
*/
public class AbstractMethod {
}
public abstract class A {
abstract void f1();
public static void main(String[] args)
{
A a = new B();
b.f1();
//A a = new B();
a.f1();
D d = new D();
d.f1();
d.f2();
A[] a1 = new A[3];
A[] a1= new A[2];
}
}
class B extends A {
@Override
void f1() {
System.out.println("f1");
}
}
class C extends A {
@Override
void f2() {
System.out.println("f2");
}
}
class D extends C {
void f3() {
System.out.println("f3");
}
}
abstract class E extends B {
@Override
void f1() {
System.out.println("f1");
}
@Override
void x() {
System.out.println("x");
}
}
abstract class F extends A {
@Override
void f1() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
abstract void x();
}
}

View File

@ -0,0 +1,39 @@
/*
* 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.calebfontenot.abstractmethod;
/**
*
* @author caleb
*/
import java.util.ArrayList;
import java.math.*;
public class LargestNumbers {
public static void main(String[] args) {
ArrayList<Number> list = new ArrayList<Number>();
list.add(45); // Add an integer
list.add(3445.53); // Add a double
// Add a BigInteger
list.add(new BigInteger("3432323234344343101"));
// Add a BigDecimal
list.add(new BigDecimal("2.0909090989091343433344343"));
System.out.println("The largest number is " +
getLargestNumber(list));
}
public static Number getLargestNumber(ArrayList<Number> list) {
if (list == null || list.size() == 0)
return null;
Number number = list.get(0);
for (int i = 1; i < list.size(); i++)
if (number.doubleValue() < list.get(i).doubleValue())
number = list.get(i);
return number;
}
}

View File

@ -0,0 +1,48 @@
/*
* 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.calebfontenot.abstractmethod;
/**
*
* @author caleb
*/
import java.util.*;
public class TestCalendar {
public static void main(String[] args)
{
// Construct a Gregorian calendar for the current date and time
Calendar calendar = new GregorianCalendar();
System.out.println("Current time is " + new Date());
System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
System.out.println("DATE: " + calendar.get(Calendar.DATE));
System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
System.out.println("HOUR_OF_DAY: "
+ calendar.get(Calendar.HOUR_OF_DAY));
System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));
System.out.println("SECOND: " + calendar.get(Calendar.SECOND));
System.out.println("DAY_OF_WEEK: "
+ calendar.get(Calendar.DAY_OF_WEEK));
System.out.println("DAY_OF_MONTH: "
+ calendar.get(Calendar.DAY_OF_MONTH));
System.out.println("DAY_OF_YEAR: "
+ calendar.get(Calendar.DAY_OF_YEAR));
System.out.println("WEEK_OF_MONTH: "
+ calendar.get(Calendar.WEEK_OF_MONTH));
System.out.println("WEEK_OF_YEAR: "
+ calendar.get(Calendar.WEEK_OF_YEAR));
System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM));
// Construct a calendar for September 11, 2001
Calendar calendar1 = new GregorianCalendar(2001, 8, 11);
String[] dayNameOfWeek = {"Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"};
System.out.println("September 11, 2001 is a "
+ dayNameOfWeek[calendar1.get(Calendar.DAY_OF_WEEK) - 1]);
System.out.println(calendar1.get(Calendar.MONTH));
}
}

View File

@ -0,0 +1,2 @@
/home/caleb/ASDV-WebDev/Assignments/JavaScript/AbstractMethod/src/main/java/com/calebfontenot/abstractmethod/LargestNumbers.java
/home/caleb/ASDV-WebDev/Assignments/JavaScript/AbstractMethod/src/main/java/com/calebfontenot/abstractmethod/AbstractMethod.java

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.calebfontenot</groupId>
<artifactId>lab8_2_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.calebfontenot.lab8_2_calebfontenot.Lab8_2_CalebFontenot</exec.mainClass>
</properties>
</project>

View File

@ -0,0 +1,16 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
*/
package com.calebfontenot.lab8_2_calebfontenot;
/**
*
* @author caleb
*/
public class Lab8_2_CalebFontenot {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}

View File

@ -0,0 +1,42 @@
/*
* 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.calebfontenot.lab8_2_calebfontenot;
/**
*
* @author caleb
*/
public class NumberX implements Comparable<NumberX> {
int x;
public NumberX(int x) {
this.x = x;
}
@Override
public int compareTo(NumberX o)
{
if (this.x == o.x) {
return 0;
} else if (this.x > o.x) {
return 1;
} else {
return -1;
}
}
public static void main(String[] args)
{
NumberX x1 = new NumberX(10);
NumberX x2 = new NumberX(20);
NumberX x3 = new NumberX(30);
System.out.println(x1.compareTo(x2));
System.out.println(x1.compareTo(x3));
System.out.println(x2.compareTo(x1));
}
@Override
public String toString()
{
return "NumberX{" + "x=" + x + '}';
}
}

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.calebfontenot.lab8_2_calebfontenot;
/**
*
* @author caleb
*/
import java.math.*;
import java.util.Arrays;
public class SortComparableObjects {
public static void main(String[] args) {
NumberX[] numbers = {new NumberX(20), new NumberX(1), new NumberX(3)};
Arrays.sort(numbers);
for (NumberX number: numbers) {
System.out.println(number);
}
String[] cities = {"Savannah", "Boston", "Atlanta", "Tampa"};
java.util.Arrays.sort(cities);
for (String city: cities)
System.out.print(city + " ");
System.out.println();
BigInteger[] hugeNumbers = {new BigInteger("2323231092923992"),
new BigInteger("432232323239292"),
new BigInteger("54623239292")};
java.util.Arrays.sort(hugeNumbers);
for (BigInteger number: hugeNumbers)
System.out.print(number + " ");
}
}

View File

@ -0,0 +1,13 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
*/
package com.calebfontenot.lab8_2_calebfontenot.interfacesGrouped;
/**
*
* @author caleb
*/
public interface Interface1 {
abstract void I1();
}

View File

@ -0,0 +1,13 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
*/
package com.calebfontenot.lab8_2_calebfontenot.interfacesGrouped;
/**
*
* @author caleb
*/
public interface Interface2 {
abstract void I2();
}

View File

@ -0,0 +1,23 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
*/
package com.calebfontenot.lab8_2_calebfontenot.interfacesGrouped;
/**
*
* @author caleb
*/
public interface InterfaceGrouped1 extends Interface1, Interface2 {
int x = 10; //public static shared by all who implement or extend the interface
abstract void IG1();
static void staticMethodOfInterface() {
System.out.println("A static method inside an Interface is shared by every class" +
" that implements Interface InterfaceGrouped1.");
}
default void defaultMethodOfInterface() {
System.out.println("The default implementation was used as there was no overriding" +
" by a class that was implemented the Interface InterfaceGrouped1.");
}
}

View File

@ -0,0 +1,39 @@
/*
* 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.calebfontenot.lab8_2_calebfontenot.interfacesGrouped;
/**
*
* @author caleb
*/
public class TestInterfaces implements InterfaceGrouped1 {
@Override
public void IG1() {
System.out.println("TestInterfaces:IG1()");
}
@Override
public void I1() {
System.out.println("TestInterfaces:I1()");
}
@Override
public void I2() {
System.out.println("testInterfaces:I2()");
}
@Override
public void defaultMethodOfInterface() {
System.out.println("overriden implementation of defaultMethodOfInterface");
}
public static void main(String[] args)
{
System.out.println(TestInterfaces.x);
InterfaceGrouped1.staticMethodOfInterface();
TestInterfaces ti = new TestInterfaces();
ti.I1();
ti.I2();
ti.IG1();
ti.defaultMethodOfInterface();
}
}

View File

@ -0,0 +1,14 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
*/
package com.calebfontenot.lab8_2_calebfontenot.interfacesGrouped.fun;
/**
*
* @author caleb
*/
public interface European extends Language, Religion, War {
void whatCountry();
}

View File

@ -0,0 +1,41 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
*/
package com.calebfontenot.lab8_2_calebfontenot.interfacesGrouped.fun;
/**
*
* @author caleb
*/
public class French implements European
{
@Override
public void whatCountry() {
System.out.println("+++ I am from France! +++");
}
@Override
public void speakLanguage()
{
System.out.println("speak French");
}
@Override
public void practiceReligion()
{
System.out.println("Roman Catholic");
}
@Override
public void WWI()
{
System.out.println("In WW1 the French won -- Allies!");
}
@Override
public void WWII()
{
System.out.println("In WW2 the French wan -- Allies!");
}
}

View File

@ -0,0 +1,43 @@
/*
* 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.calebfontenot.lab8_2_calebfontenot.interfacesGrouped.fun;
/**
*
* @author caleb
*/
public class German implements European {
@Override
public void whatCountry()
{
System.out.println("+++ I am from Germany! +++");
}
@Override
public void speakLanguage()
{
System.out.println("speak German");
}
@Override
public void practiceReligion()
{
System.out.println("Protestant");
}
@Override
public void WWI()
{
System.out.println("in WW1 the Germans lost -- Axis!");
}
@Override
public void WWII()
{
System.out.println("in WW2 the Germans lost -- Axis!");
}
}

View File

@ -0,0 +1,43 @@
/*
* 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.calebfontenot.lab8_2_calebfontenot.interfacesGrouped.fun;
/**
*
* @author caleb
*/
public class Italian implements European {
@Override
public void whatCountry()
{
System.out.println("+++ I am from Itally! +++");
}
@Override
public void speakLanguage()
{
System.out.println("speak Italian");
}
@Override
public void practiceReligion()
{
System.out.println("paganism");
}
@Override
public void WWI()
{
System.out.println("in WW1 the Italians won -- Allies!");
}
@Override
public void WWII()
{
System.out.println("In WW2 the Italians lost -- Axis!");
}
}

View File

@ -0,0 +1,13 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
*/
package com.calebfontenot.lab8_2_calebfontenot.interfacesGrouped.fun;
/**
*
* @author caleb
*/
public interface Language {
void speakLanguage();
}

View File

@ -0,0 +1,16 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
*/
package com.calebfontenot.lab8_2_calebfontenot.interfacesGrouped.fun;
/**
*
* @author caleb
*/
public interface Religion {
public void practiceReligion();
default void beforeChrist() {
System.out.println("paganism");
}
}

View File

@ -0,0 +1,43 @@
/*
* 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.calebfontenot.lab8_2_calebfontenot.interfacesGrouped.fun;
/**
*
* @author caleb
*/
public class Russian implements European {
@Override
public void whatCountry()
{
System.out.println("+++ I am from Russia! +++");
}
@Override
public void speakLanguage()
{
System.out.println("speak Russian");
}
@Override
public void practiceReligion()
{
System.out.println("Orthodox");
}
@Override
public void WWI()
{
System.out.println("In WW1 the Russians won -- Allies!");
}
@Override
public void WWII()
{
System.out.println("In WW2 the Russians won -- Allies!");
}
}

View File

@ -0,0 +1,60 @@
/*
* 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.calebfontenot.lab8_2_calebfontenot.interfacesGrouped.fun;
import java.util.ArrayList;
/**
*
* @author caleb
*/
public class TestEuropeans {
public static void testWithArrayList()
{
ArrayList<European> europeans = new ArrayList();
europeans.add(new French());
europeans.add(new German());
europeans.add(new Russian());
europeans.add(new Italian());
for(European man: europeans) {
man.whatCountry();
man.beforeChrist();
man.practiceReligion();
man.speakLanguage();
man.WWI();
man.WWII();
}
}
public static void testWithArrayOfObjects() {
European[] europeans = {
new French(),
new German(),
new Russian(),
new Italian()
};
for (European person: europeans) {
person.whatCountry();
person.beforeChrist();
person.practiceReligion();
person.speakLanguage();
person.WWI();
person.WWII();
}
}
public static void testWithArrayOfInterfaces() {
Interface[] interfaceArr = {
}
}
public static void main(String[] args)
{
testWithArrayList();
System.out.println("-------------------");
testWithArrayOfObjects();
}
}

View File

@ -0,0 +1,14 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
*/
package com.calebfontenot.lab8_2_calebfontenot.interfacesGrouped.fun;
/**
*
* @author caleb
*/
public interface War {
void WWI();
void WWII();
}

View File

@ -0,0 +1,38 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Animal.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: #ffc66d}
.comment {color: #808080}
.whitespace {color: #505050}
.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/caleb/ASDV-Java/Semester 2/Assignments/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Animal.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.lab8_calebfontenot;
<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">abstract</span> <span class="literal">class</span> Animal {
<span class="literal">public</span> <span class="literal">abstract</span> String <span class="ST2">sound</span>();
}
</pre></body>
</html>

View File

@ -0,0 +1,44 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Apple.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: #ffc66d}
.string {color: #6a8759}
.comment {color: #808080}
.whitespace {color: #505050}
.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/caleb/ASDV-Java/Semester 2/Assignments/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Apple.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.lab8_calebfontenot;
<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> Apple <span class="literal">extends</span> Fruit{
@Override
<span class="literal">public</span> String <span class="ST2">howToEat</span>()
{
<span class="literal">return</span> <span class="string">&quot;</span><span class="string">Apple: Make apple cider.</span><span class="string">&quot;</span>;
}
}
</pre></body>
</html>

View File

@ -0,0 +1,42 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Brocoli.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: #ffc66d}
.string {color: #6a8759}
.comment {color: #808080}
.whitespace {color: #505050}
.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/caleb/ASDV-Java/Semester 2/Assignments/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Brocoli.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.lab8_calebfontenot;
<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> Brocoli <span class="literal">extends</span> Fruit {
@Override
<span class="literal">public</span> String <span class="ST2">howToEat</span>() {
<span class="literal">return</span> <span class="string">&quot;</span><span class="string">Brocolli: Steam it</span><span class="string">&quot;</span>;
}
}
</pre></body>
</html>

View File

@ -0,0 +1,47 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Chicken.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}
.ST3 {color: #ffc66d}
.string {color: #6a8759}
.comment {color: #808080}
.whitespace {color: #505050}
.ST1 {color: #808080; font-family: monospace; font-weight: bold}
.ST0 {color: #287bde}
.literal {color: #cc7832}
.ST2 {font-family: monospace; font-style: italic}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 2/Assignments/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Chicken.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.lab8_calebfontenot;
<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> Chicken <span class="literal">extends</span> <span class="ST2">Animal</span> <span class="literal">implements</span> Edible {
@Override
<span class="literal">public</span> String <span class="ST3">sound</span>() {
<span class="literal">return</span> <span class="string">&quot;</span><span class="string">Chicken: cock-a-doodle-do!</span><span class="string">&quot;</span>;
}
@Override
<span class="literal">public</span> String <span class="ST3">howToEat</span>() {
<span class="literal">return</span> <span class="string">&quot;</span><span class="string">Chicken: Fry it!</span><span class="string">&quot;</span>;
}
}
</pre></body>
</html>

View File

@ -0,0 +1,47 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Duck.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: #ffc66d}
.string {color: #6a8759}
.comment {color: #808080}
.whitespace {color: #505050}
.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/caleb/ASDV-Java/Semester 2/Assignments/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Duck.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.lab8_calebfontenot;
<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> Duck <span class="literal">extends</span> Animal <span class="literal">implements</span> Edible {
@Override
<span class="literal">public</span> String <span class="ST2">howToEat</span>() {
<span class="literal">return</span> <span class="string">&quot;</span><span class="string">Duck: Roast it!</span><span class="string">&quot;</span>;
}
@Override
<span class="literal">public</span> String <span class="ST2">sound</span>() {
<span class="literal">return</span> <span class="string">&quot;</span><span class="string">Duck: Quack! Quack! Quack!</span><span class="string">&quot;</span>;
}
}
</pre></body>
</html>

View File

@ -0,0 +1,39 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Edible.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}
.ST3 {color: #ffc66d}
.comment {color: #808080}
.whitespace {color: #505050}
.ST1 {color: #808080; font-family: monospace; font-weight: bold}
.ST0 {color: #287bde}
.literal {color: #cc7832}
.ST2 {font-family: monospace; font-weight: bold}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 2/Assignments/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Edible.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/Interface.java</span><span class="comment"> to edit this template</span>
<span class="comment"> */</span>
<span class="literal">package</span> com.calebfontenot.lab8_calebfontenot;
<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">interface</span> <span class="ST2">Edible</span> {
String <span class="ST3">howToEat</span>();
}
</pre></body>
</html>

View File

@ -0,0 +1,37 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Fruit.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}
.comment {color: #808080}
.whitespace {color: #505050}
.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/caleb/ASDV-Java/Semester 2/Assignments/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Fruit.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.lab8_calebfontenot;
<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">abstract</span> <span class="literal">class</span> Fruit <span class="literal">implements</span> Edible{
}
</pre></body>
</html>

View File

@ -0,0 +1,164 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>House.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}
.ST4 {color: #8a653b}
.ST0 {color: #287bde}
.literal {color: #cc7832}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 2/Assignments/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/House.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.lab8_calebfontenot;
<span class="literal">import</span> java.util.Date;
<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> House <span class="literal">implements</span> Cloneable{
<span class="literal">private</span> <span class="literal">int</span> <span class="ST2">id</span>;
<span class="literal">private</span> <span class="literal">double</span> <span class="ST2">area</span>;
<span class="literal">private</span> Date <span class="ST2">whenBuilt</span>;
<span class="literal">public</span> House(<span class="literal">int</span> id, <span class="literal">double</span> area)
{
<span class="literal">this</span>.<span class="ST2">id</span> = id;
<span class="literal">this</span>.<span class="ST2">area</span> = area;
<span class="literal">this</span>.<span class="ST2">whenBuilt</span> = <span class="literal">new</span> Date();
}
@Override
<span class="literal">protected</span> Object <span class="ST3">clone</span>() <span class="literal">throws</span> CloneNotSupportedException
{
Object o = <span class="literal">super</span>.clone();
((House) o).<span class="ST2">whenBuilt</span> = <span class="literal">new</span> Date(<span class="literal">t</span><span class="literal">his</span>.<span class="ST2">whenBuilt</span>.getTime());
<span class="literal">return</span> o;
}
<span class="comment">/**</span>
<span class="comment"> * </span><span class="comment">Get</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">whenBuilt</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST1">@return</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">whenBuilt</span>
<span class="comment">*/</span>
<span class="literal">public</span> Date <span class="ST3">getWhenBuilt</span>()
{
<span class="literal">return</span> <span class="ST2">whenBuilt</span>;
}
<span class="comment">/**</span>
<span class="comment"> * </span><span class="comment">Set</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">whenBuilt</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST1">@param</span> <span class="ST4">whenBuilt</span> <span class="comment">new</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">whenBuilt</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">void</span> <span class="ST3">setWhenBuilt</span>(Date whenBuilt)
{
<span class="literal">this</span>.<span class="ST2">whenBuilt</span> = whenBuilt;
}
<span class="comment">/**</span>
<span class="comment"> * </span><span class="comment">Get</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">area</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST1">@return</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">area</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">double</span> <span class="ST3">getArea</span>()
{
<span class="literal">return</span> <span class="ST2">area</span>;
}
<span class="comment">/**</span>
<span class="comment"> * </span><span class="comment">Set</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">area</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST1">@param</span> <span class="ST4">area</span> <span class="comment">new</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">area</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">void</span> <span class="ST3">setArea</span>(<span class="literal">double</span> area)
{
<span class="literal">this</span>.<span class="ST2">area</span> = area;
}
<span class="comment">/**</span>
<span class="comment"> * </span><span class="comment">Get</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">id</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST1">@return</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">id</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">int</span> <span class="ST3">getId</span>()
{
<span class="literal">return</span> <span class="ST2">id</span>;
}
<span class="comment">/**</span>
<span class="comment"> * </span><span class="comment">Set</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">id</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST1">@param</span> <span class="ST4">id</span> <span class="comment">new</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">id</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">void</span> <span class="ST3">setId</span>(<span class="literal">int</span> id)
{
<span class="literal">this</span>.<span class="ST2">id</span> = id;
}
@Override
<span class="literal">public</span> String <span class="ST3">toString</span>()
{
<span class="literal">return</span> <span class="string">&quot;</span><span class="string">House{</span><span class="string">&quot;</span> + <span class="string">&quot;</span><span class="string">id=</span><span class="string">&quot;</span> + <span class="ST2">id</span> + <span class="string">&quot;</span><span class="string">, area=</span><span class="string">&quot;</span> + <span class="ST2">area</span> + <span class="string">&quot;</span><span class="string">, whenBuilt=</span><span class="string">&quot;</span> + <span class="ST2">whenBuilt</span> + <span class="string">&#39;</span><span class="string">}</span><span class="string">&#39;</span>;
}
<span class="literal">public</span> <span class="literal">int</span> <span class="ST3">compareTo</span>(House o) {
<span class="literal">if</span> (<span class="literal">this</span>.getId() == o.getId() &amp;&amp;
<span class="literal">this</span>.getArea() == o.getArea() &amp;&amp;
<span class="literal">this</span>.getWhenBuilt().equals(o.getWhenBuilt())) {
<span class="literal">return</span> <span class="number">0</span>;
}
<span class="literal">if</span> (<span class="literal">this</span>.<span class="ST2">area</span> &gt; o.<span class="ST2">area</span>) {
<span class="literal">return</span> <span class="number">1</span>;
} <span class="literal">else</span> <span class="literal">if</span> (<span class="literal">this</span>.<span class="ST2">area</span> &lt; o.<span class="ST2">area</span>) {
<span class="literal">return</span> -<span class="number">1</span>;
} <span class="literal">else</span> {
<span class="literal">return</span> -<span class="number">2</span>; <span class="comment">// Same area for this and o but either var id or var whenBuilt are different</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, InterruptedException {
House house1 = <span class="literal">new</span> House(<span class="number">1</span>, <span class="number">1</span><span class="number">000</span>);
House house2 = (House) house1.clone();
house2.<span class="ST2">whenBuilt</span>.setDate(<span class="number">8</span>);
System.<span class="ST6">out</span>.println(house1);
System.<span class="ST6">out</span>.println(house2);
House house3 = <span class="literal">new</span> House(<span class="number">3</span>, <span class="number">2</span><span class="number">000</span>);
House house4 = <span class="literal">new</span> House(<span class="number">4</span>, <span class="number">2</span><span class="number">000</span>);
System.<span class="ST6">out</span>.println(<span class="string">&quot;</span><span class="string">house 1 and house 2 are identical: </span><span class="string">&quot;</span>+ house1.compareTo(house2));
System.<span class="ST6">out</span>.println(<span class="string">&quot;</span><span class="string">house 3 and house 3 have the same area: </span><span class="string">&quot;</span> + house3.compareTo(house4));
System.<span class="ST6">out</span>.println(<span class="string">&quot;</span><span class="string">House 4 is harger than house 2: </span><span class="string">&quot;</span> + house4.compareTo(house2));
}
}
</pre></body>
</html>

View File

@ -0,0 +1,45 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Orange.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: #ffc66d}
.string {color: #6a8759}
.comment {color: #808080}
.whitespace {color: #505050}
.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/caleb/ASDV-Java/Semester 2/Assignments/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Orange.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.lab8_calebfontenot;
<span class="literal">import</span> com.calebfontenot.lab8_calebfontenot.Fruit;
<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> Orange <span class="literal">extends</span> Fruit {
@Override
<span class="literal">public</span> String <span class="ST2">howToEat</span>() {
<span class="literal">return</span> <span class="string">&quot;</span><span class="string">Orange: Make orange juice.</span><span class="string">&quot;</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>Test.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: #ffc66d}
.string {color: #6a8759}
.comment {color: #808080}
.whitespace {color: #505050}
.ST3 {color: #ffc66d; 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/caleb/ASDV-Java/Semester 2/Assignments/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Test.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.lab8_calebfontenot;
<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> Test {
Edible <span class="comment">getEdible</span>() {
Edible e = <span class="literal">new</span> Edible() {
@Override
<span class="literal">public</span> String <span class="ST2">howToEat</span>() {
<span class="literal">return</span> <span class="string">&quot;</span><span class="string">Beans: make a soup</span><span class="string">&quot;</span>;
}
};
<span class="literal">return</span> e;
}
<span class="comment">/*</span>
<span class="comment">Comparable getComparable() {</span>
<span class="comment"> Comparable c = new Comparable() {</span>
<span class="comment"> @Override</span>
<span class="comment"> public int compareTo(Object o) {</span>
<span class="comment"> return == &quot;dummy value&quot; ? ((o.hashCode() == 11 ? 1 : -1) : 0;</span>
<span class="comment"> }</span>
<span class="comment"> };</span>
<span class="comment"> return c;</span>
<span class="comment"> }</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST3">main</span>(String[] args)
{
Edible[] <span class="comment">edible</span> = {<span class="literal">new</span> Chicken()};
}
}
</pre></body>
</html>

View File

@ -0,0 +1,90 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>TestEdible.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}
.ST4 {color: #9876aa}
.number {color: #6897bb}
.string {color: #6a8759}
.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}
.ST5 {font-family: monospace; font-style: italic}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 2/Assignments/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/TestEdible.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.lab8_calebfontenot;
<span class="literal">import</span> java.util.ArrayList;
<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> TestEdible {
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST2">testWithArrayList</span>() {
ArrayList&lt;Edible&gt; edible = <span class="literal">new</span> ArrayList();
edible.add(<span class="literal">new</span> Chicken());
edible.add(<span class="literal">new</span> Apple());
edible.add(<span class="literal">new</span> Orange());
edible.add(<span class="literal">new</span> Duck());
edible.add(<span class="literal">new</span> Brocoli());
<span class="literal">for</span> (Edible eat: edible) {
System.<span class="ST3">out</span>.println(eat.howToEat());
}
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST2">testWithArrayOfInterfaces</span>() {
Edible[] edible = {
<span class="literal">new</span> Chicken(), <span class="literal">new</span> Apple(), <span class="literal">new</span> Orange(), <span class="literal">new</span> Duck(), <span class="literal">new</span> Brocoli()
};
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i &lt; edible.<span class="ST4">length</span>; ++i) {
System.<span class="ST3">out</span>.println(edible[i].howToEat());
}
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST2">testWithArrayOfObjects</span>() {
Object[] objects = {
<span class="literal">new</span> Tiger(), <span class="literal">new</span> Chicken(), <span class="literal">new</span> Apple(), <span class="literal">new</span> Duck(), <span class="literal">new</span> Brocoli()
};
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i &lt; objects.<span class="ST4">length</span>; ++i) {
<span class="literal">if</span> (objects[i] <span class="literal">instanceof</span> Edible) {
System.<span class="ST3">out</span>.println(((Edible) objects[i]).howToEat());
}
<span class="literal">if</span> (objects[i] <span class="literal">instanceof</span> Animal) {
System.<span class="ST3">out</span>.println(((Animal) objects[i]).sound());
}
}
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST2">main</span>(String[] args)
{
<span class="ST5">testWithArrayOfObjects</span>();
System.<span class="ST3">out</span>.println(<span class="string">&quot;</span><span class="string">-------------------</span><span class="string">&quot;</span>);
<span class="ST5">testWithArrayOfInterfaces</span>();
System.<span class="ST3">out</span>.println(<span class="string">&quot;</span><span class="string">------------------ </span><span class="string">&quot;</span>);
<span class="ST5">testWithArrayList</span>();
}
}
</pre></body>
</html>

View File

@ -0,0 +1,46 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Tiger.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}
.ST3 {color: #ffc66d}
.string {color: #6a8759}
.comment {color: #808080}
.whitespace {color: #505050}
.ST1 {color: #808080; font-family: monospace; font-weight: bold}
.ST0 {color: #287bde}
.literal {color: #cc7832}
.ST2 {font-family: monospace; font-style: italic}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 2/Assignments/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Tiger.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.lab8_calebfontenot;
<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> Tiger <span class="literal">extends</span> <span class="ST2">Animal</span> {
@Override
<span class="literal">public</span> String <span class="ST3">sound</span>()
{
<span class="literal">return</span> <span class="string">&quot;</span><span class="string">Tiger: ROAAAAAAAR!</span><span class="string">&quot;</span>;
}
}
</pre></body>
</html>

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.calebfontenot</groupId>
<artifactId>lab8_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.calebfontenot.lab8_calebfontenot.Lab8_CalebFontenot</exec.mainClass>
</properties>
</project>

View File

@ -0,0 +1,13 @@
/*
* 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.calebfontenot.lab8_calebfontenot;
/**
*
* @author caleb
*/
public abstract class Animal {
public abstract String sound();
}

View File

@ -0,0 +1,18 @@
/*
* 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.calebfontenot.lab8_calebfontenot;
/**
*
* @author caleb
*/
public class Apple extends Fruit{
@Override
public String howToEat()
{
return "Apple: Make apple cider.";
}
}

View File

@ -0,0 +1,16 @@
/*
* 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.calebfontenot.lab8_calebfontenot;
/**
*
* @author caleb
*/
public class Brocoli extends Fruit {
@Override
public String howToEat() {
return "Brocolli: Steam it";
}
}

View File

@ -0,0 +1,20 @@
/*
* 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.calebfontenot.lab8_calebfontenot;
/**
*
* @author caleb
*/
public class Chicken extends Animal implements Edible {
@Override
public String sound() {
return "Chicken: cock-a-doodle-do!";
}
@Override
public String howToEat() {
return "Chicken: Fry it!";
}
}

View File

@ -0,0 +1,21 @@
/*
* 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.calebfontenot.lab8_calebfontenot;
/**
*
* @author caleb
*/
public class Duck extends Animal implements Edible {
@Override
public String howToEat() {
return "Duck: Roast it!";
}
@Override
public String sound() {
return "Duck: Quack! Quack! Quack!";
}
}

View File

@ -0,0 +1,13 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
*/
package com.calebfontenot.lab8_calebfontenot;
/**
*
* @author caleb
*/
public interface Edible {
String howToEat();
}

View File

@ -0,0 +1,13 @@
/*
* 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.calebfontenot.lab8_calebfontenot;
/**
*
* @author caleb
*/
public abstract class Fruit implements Edible{
}

View File

@ -0,0 +1,133 @@
/*
* 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.calebfontenot.lab8_calebfontenot;
import java.util.Date;
/**
*
* @author caleb
*/
public class House implements Cloneable{
private int id;
private double area;
private Date whenBuilt;
public House(int id, double area)
{
this.id = id;
this.area = area;
this.whenBuilt = new Date();
}
@Override
protected Object clone() throws CloneNotSupportedException
{
Object o = super.clone();
((House) o).whenBuilt = new Date(this.whenBuilt.getTime());
return o;
}
/**
* Get the value of whenBuilt
*
* @return the value of whenBuilt
*/
public Date getWhenBuilt()
{
return whenBuilt;
}
/**
* Set the value of whenBuilt
*
* @param whenBuilt new value of whenBuilt
*/
public void setWhenBuilt(Date whenBuilt)
{
this.whenBuilt = whenBuilt;
}
/**
* Get the value of area
*
* @return the value of area
*/
public double getArea()
{
return area;
}
/**
* Set the value of area
*
* @param area new value of area
*/
public void setArea(double area)
{
this.area = area;
}
/**
* Get the value of id
*
* @return the value of id
*/
public int getId()
{
return id;
}
/**
* Set the value of id
*
* @param id new value of id
*/
public void setId(int id)
{
this.id = id;
}
@Override
public String toString()
{
return "House{" + "id=" + id + ", area=" + area + ", whenBuilt=" + whenBuilt + '}';
}
public int compareTo(House o) {
if (this.getId() == o.getId() &&
this.getArea() == o.getArea() &&
this.getWhenBuilt().equals(o.getWhenBuilt())) {
return 0;
}
if (this.area > o.area) {
return 1;
} else if (this.area < o.area) {
return -1;
} else {
return -2; // Same area for this and o but either var id or var whenBuilt are different
}
}
public static void main(String[] args) throws CloneNotSupportedException, InterruptedException {
House house1 = new House(1, 1000);
House house2 = (House) house1.clone();
house2.whenBuilt.setDate(8);
System.out.println(house1);
System.out.println(house2);
House house3 = new House(3, 2000);
House house4 = new House(4, 2000);
System.out.println("house 1 and house 2 are identical: "+ house1.compareTo(house2));
System.out.println("house 3 and house 3 have the same area: " + house3.compareTo(house4));
System.out.println("House 4 is harger than house 2: " + house4.compareTo(house2));
}
}

View File

@ -0,0 +1,16 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
*/
package com.calebfontenot.lab8_calebfontenot;
/**
*
* @author caleb
*/
public class Lab8_CalebFontenot {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}

View File

@ -0,0 +1,19 @@
/*
* 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.calebfontenot.lab8_calebfontenot;
import com.calebfontenot.lab8_calebfontenot.Fruit;
/**
*
* @author caleb
*/
public class Orange extends Fruit {
@Override
public String howToEat() {
return "Orange: Make orange juice.";
}
}

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.calebfontenot.lab8_calebfontenot;
/**
*
* @author caleb
*/
public class Test {
Edible getEdible() {
Edible e = new Edible() {
@Override
public String howToEat() {
return "Beans: make a soup";
}
};
return e;
}
/*
Comparable getComparable() {
Comparable c = new Comparable() {
@Override
public int compareTo(Object o) {
return == "dummy value" ? ((o.hashCode() == 11 ? 1 : -1) : 0;
}
};
return c;
}
*/
public static void main(String[] args)
{
Edible[] edible = {new Chicken()};
}
}

View File

@ -0,0 +1,60 @@
/*
* 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.calebfontenot.lab8_calebfontenot;
import java.util.ArrayList;
/**
*
* @author caleb
*/
public class TestEdible {
public static void testWithArrayList() {
ArrayList<Edible> edible = new ArrayList();
edible.add(new Chicken());
edible.add(new Apple());
edible.add(new Orange());
edible.add(new Duck());
edible.add(new Brocoli());
for (Edible eat: edible) {
System.out.println(eat.howToEat());
}
}
public static void testWithArrayOfInterfaces() {
Edible[] edible = {
new Chicken(), new Apple(), new Orange(), new Duck(), new Brocoli()
};
for (int i = 0; i < edible.length; ++i) {
System.out.println(edible[i].howToEat());
}
}
public static void testWithArrayOfObjects() {
Object[] objects = {
new Tiger(), new Chicken(), new Apple(), new Duck(), new Brocoli()
};
for (int i = 0; i < objects.length; ++i) {
if (objects[i] instanceof Edible) {
System.out.println(((Edible) objects[i]).howToEat());
}
if (objects[i] instanceof Animal) {
System.out.println(((Animal) objects[i]).sound());
}
}
}
public static void main(String[] args)
{
testWithArrayOfObjects();
System.out.println("-------------------");
testWithArrayOfInterfaces();
System.out.println("------------------ ");
testWithArrayList();
}
}

View File

@ -0,0 +1,19 @@
/*
* 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.calebfontenot.lab8_calebfontenot;
/**
*
* @author caleb
*/
public class Tiger extends Animal {
@Override
public String sound()
{
return "Tiger: ROAAAAAAAR!";
}
}