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

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();
}