Markou is absolutely insane
This commit is contained in:
parent
aa46f43ea5
commit
aef4bcc29c
4
.gitignore
vendored
4
.gitignore
vendored
@ -194,3 +194,7 @@
|
||||
/Semester 3/Assignments/LinkedList/build/
|
||||
/Semester 3/Assignments/MP6_CalebFontenot/target/
|
||||
/Semester 3/Assignments/Lab_CalebFontenot_MaximumOrderedString/target/
|
||||
/Semester 4/EnumDemo/target/
|
||||
/Semester 4/Assignments/DAO/target/
|
||||
/Semester 4/Assignments/ProjectTrees_CalebFontenot/target/
|
||||
/Semester 4/Assignments/DataStructures/target/
|
||||
|
@ -6,6 +6,7 @@ package edu.slcc.asdv.caleb.lab_calebfontenot_maximumorderedstring;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -21,7 +22,7 @@ public class FindMaxOrderedSubstring {
|
||||
outputString += input.charAt(i);
|
||||
}
|
||||
if (input.charAt(i) > outputString.charAt(j)) {
|
||||
++j;
|
||||
System.out.println(++j);
|
||||
outputString += input.charAt(i);
|
||||
}
|
||||
}
|
||||
@ -29,6 +30,9 @@ public class FindMaxOrderedSubstring {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(findMaxOrderedSubString("Welcome!"));
|
||||
Scanner input = new Scanner(System.in);
|
||||
System.out.print("Enter a string: ");
|
||||
String inputStr = input.nextLine();
|
||||
System.out.println(findMaxOrderedSubString(inputStr));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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 edu.slcc.asdv.caleb.lab_calebfontenot_maximumorderedstring;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
import java.util.Comparator;
|
||||
|
||||
public class GenericMergeSort {
|
||||
|
||||
public static <E extends Comparable<E>> void mergeSort(E[] list)
|
||||
{
|
||||
mergeSort(list,
|
||||
new Comparator<E>() {
|
||||
@Override
|
||||
public int compare(E e1, E e2)
|
||||
{
|
||||
return ((Comparable<E>) e1).compareTo(e2);
|
||||
}
|
||||
});
|
||||
}
|
||||
static int recursiveCallCount = 0;
|
||||
public static <E> void mergeSort(E[] list,
|
||||
Comparator<? super E> comparator)
|
||||
{
|
||||
|
||||
if (list.length > 1) {
|
||||
recursiveCallCount++;
|
||||
// Merge sort the first half
|
||||
E[] firstHalf = (E[]) new Object[list.length / 2];
|
||||
System.arraycopy(list, 0, firstHalf, 0, list.length / 2);
|
||||
mergeSort(firstHalf, comparator);
|
||||
|
||||
// Merge sort the second half
|
||||
int secondHalfLength = list.length - list.length / 2;
|
||||
E[] secondHalf = (E[]) new Object[secondHalfLength];
|
||||
System.arraycopy(list, list.length / 2,
|
||||
secondHalf, 0, secondHalfLength);
|
||||
mergeSort(secondHalf, comparator);
|
||||
|
||||
// Merge firstHalf with secondHalf
|
||||
E[] temp = merge1(firstHalf, secondHalf, comparator);
|
||||
System.arraycopy(temp, 0, list, 0, temp.length);
|
||||
}
|
||||
}
|
||||
|
||||
private static <E> E[]
|
||||
merge1(E[] list1, E[] list2, Comparator<? super E> comparator)
|
||||
{
|
||||
E[] temp = (E[]) new Object[list1.length + list2.length];
|
||||
|
||||
int current1 = 0; // Index in list1
|
||||
int current2 = 0; // Index in list2
|
||||
int current3 = 0; // Index in temp
|
||||
|
||||
while (current1 < list1.length && current2 < list2.length) {
|
||||
if (comparator.compare(list1[current1], list2[current2]) < 0) {
|
||||
temp[current3++] = list1[current1++];
|
||||
} else {
|
||||
temp[current3++] = list2[current2++];
|
||||
}
|
||||
}
|
||||
|
||||
while (current1 < list1.length) {
|
||||
temp[current3++] = list1[current1++];
|
||||
}
|
||||
|
||||
while (current2 < list2.length) {
|
||||
temp[current3++] = list2[current2++];
|
||||
}
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
Integer[] list
|
||||
= {
|
||||
2, 3, 2, 5, 6, 1, -2, 3, 14, 12
|
||||
};
|
||||
mergeSort(list);
|
||||
System.out.println("number of recursive calls: " + recursiveCallCount);
|
||||
recursiveCallCount = 0;
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
System.out.print(list[i] + " ");
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
String[] list1
|
||||
= {
|
||||
"ABC", "abc", "abm", "Anf", "Good", "Bad", "nice"
|
||||
};
|
||||
mergeSort(list1, (s1, s2) -> s1.compareToIgnoreCase(s2));
|
||||
System.out.println("number of recursive calls: " + recursiveCallCount);
|
||||
recursiveCallCount = 0;
|
||||
for (int i = 0; i < list1.length; i++) {
|
||||
System.out.print(list1[i] + " ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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 edu.slcc.asdv.caleb.lab_calebfontenot_maximumorderedstring;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class JudeFindMax {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(consecLetters("abcabcdgabxy"));
|
||||
System.out.println(consecLetters("abcabcdgabmnsxy"));
|
||||
System.out.println(consecLetters("abchjsfhajshfhijklmnopqjfaksfhkajhsf"));
|
||||
System.out.println(consecLetters("hnafffgardghikortmmnmnmn"));
|
||||
}
|
||||
|
||||
public static String consecLetters(String input)
|
||||
{
|
||||
String consec = "";
|
||||
String maxConsec = "";
|
||||
|
||||
for (int i = 1; i < input.length(); i++) //n - 1
|
||||
{
|
||||
//If two in order
|
||||
if (input.charAt(i) > input.charAt(i - 1))
|
||||
{
|
||||
//If length is zero then add previous as well
|
||||
if (consec.length() == 0)
|
||||
consec += input.charAt(i - 1);
|
||||
consec += input.charAt(i);
|
||||
}
|
||||
//If not in order
|
||||
else
|
||||
{
|
||||
//Check current consec length against maximum length
|
||||
if (consec.length() > maxConsec.length())
|
||||
{
|
||||
//set new max
|
||||
maxConsec = consec;
|
||||
}
|
||||
consec = "";
|
||||
}
|
||||
}
|
||||
|
||||
//Check current consec length against maximum length
|
||||
if (consec.length() > maxConsec.length())
|
||||
{
|
||||
//set new max
|
||||
maxConsec = consec;
|
||||
}
|
||||
|
||||
return "Most letters found in order: " + maxConsec;
|
||||
}
|
||||
}
|
14
Semester 4/Assignments/DAO/pom.xml
Normal file
14
Semester 4/Assignments/DAO/pom.xml
Normal 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>edu.slcc.asdv.caleb</groupId>
|
||||
<artifactId>DAO</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>20</maven.compiler.source>
|
||||
<maven.compiler.target>20</maven.compiler.target>
|
||||
<exec.mainClass>edu.slcc.asdv.caleb.dao.DAO</exec.mainClass>
|
||||
</properties>
|
||||
</project>
|
20
Semester 4/Assignments/DAO/src/main/java/DAO/DAO.java
Normal file
20
Semester 4/Assignments/DAO/src/main/java/DAO/DAO.java
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* 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 DAO;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public interface DAO<T> {
|
||||
public void create(T t);
|
||||
public void delete(T t);
|
||||
public void update(T t);
|
||||
public T find (T t);
|
||||
public Collection<T> findALl();
|
||||
public boolean updateDBase();
|
||||
}
|
19
Semester 4/Assignments/DAO/src/main/java/DAO/Exam.java
Normal file
19
Semester 4/Assignments/DAO/src/main/java/DAO/Exam.java
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* 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 DAO;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public interface Exam<T> {
|
||||
void editExam(T t);
|
||||
void takeExam(T t);
|
||||
void submitExam(T t);
|
||||
void previewExam(T t);
|
||||
void monitorExam(T t);
|
||||
void gradeExam(T t);
|
||||
|
||||
}
|
@ -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 DAO;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public abstract class ExamFactory<T extends Keyable> {
|
||||
public abstract Exam<T> createExam();
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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 DAO;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class ExamFactoryOutlet<K, V extends Keyable> extends ExamFactory<Keyable> {
|
||||
|
||||
@Override
|
||||
public Exam<Keyable> createExam()
|
||||
{
|
||||
return new Exam<Keyable>() {
|
||||
@Override
|
||||
public void editExam(Keyable t)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
@Override
|
||||
public void takeExam(Keyable t)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
@Override
|
||||
public void submitExam(Keyable t)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
@Override
|
||||
public void previewExam(Keyable t)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
@Override
|
||||
public void monitorExam(Keyable t)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gradeExam(Keyable t)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
}
|
15
Semester 4/Assignments/DAO/src/main/java/DAO/Keyable.java
Normal file
15
Semester 4/Assignments/DAO/src/main/java/DAO/Keyable.java
Normal file
@ -0,0 +1,15 @@
|
||||
/*
|
||||
* 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 DAO;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public interface Keyable<K> {
|
||||
public K getKey();
|
||||
public void setKey(K key);
|
||||
|
||||
}
|
32
Semester 4/Assignments/DAO/src/main/java/DAO/MathExam.java
Normal file
32
Semester 4/Assignments/DAO/src/main/java/DAO/MathExam.java
Normal 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 DAO;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class MathExam implements Keyable<MathExam> {
|
||||
ArrayList<Object> fields = new ArrayList<Object>();
|
||||
int key;
|
||||
|
||||
public MathExam(int key, ArrayList<Object> fields) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public MathExam getKey()
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setKey(MathExam key)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
}
|
23
Semester 4/Assignments/DAO/src/main/java/DAO/Test.java
Normal file
23
Semester 4/Assignments/DAO/src/main/java/DAO/Test.java
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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 DAO;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class Test {
|
||||
public static void main(String[] args)
|
||||
{
|
||||
ExamFactory<MathExam> efm = new ExamFactory<MathExam>() {
|
||||
@Override
|
||||
public Exam<MathExam> createExam()
|
||||
{
|
||||
System.out.println("Hello World");
|
||||
}
|
||||
};
|
||||
efm.createExam();
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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 edu.slcc.asdv.caleb.dao.factory_pizza;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class CheezePizza implements Pizza {
|
||||
|
||||
@Override
|
||||
public void prepare()
|
||||
{
|
||||
System.out.println("preparing Cheeze Pizza");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bake()
|
||||
{
|
||||
System.out.println("baking Cheeze Pizza");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cut()
|
||||
{
|
||||
System.out.println("cutting Cheeze Pizza");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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 edu.slcc.asdv.caleb.dao.factory_pizza;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class ChickenPizza implements Pizza {
|
||||
|
||||
@Override
|
||||
public void prepare()
|
||||
{
|
||||
System.out.println("preparing Chicken Pizza");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bake()
|
||||
{
|
||||
System.out.println("baking Chicken Pizza");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cut()
|
||||
{
|
||||
System.out.println("cutting Chicken Pizza");
|
||||
}
|
||||
|
||||
}
|
@ -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 edu.slcc.asdv.caleb.dao.factory_pizza;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public interface Pizza<T> {
|
||||
public void prepare(T t);
|
||||
public void bake(T t);
|
||||
public void cut(T t);
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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 edu.slcc.asdv.caleb.dao.factory_pizza;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class PizzaFactory {
|
||||
|
||||
public PizzaFactory(String cheeze)
|
||||
{
|
||||
}
|
||||
public static <T> Pizza<T> createPizza(T type) throws Exception {
|
||||
Pizza p = null;
|
||||
if (type.equals("cheeze"))
|
||||
p = new CheezePizza();
|
||||
else if (type.equals("chicken"))
|
||||
p = new ChickenPizza();
|
||||
else if (type.equals("veggie"))
|
||||
p = new VeggiePizza();
|
||||
if (p == null) {
|
||||
throw new Exception("Not a valid Pizza.");
|
||||
}
|
||||
return p;
|
||||
}
|
||||
}
|
@ -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 edu.slcc.asdv.caleb.dao.factory_pizza;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class PizzaStore {
|
||||
public Pizza orderPizza(String type) throws Exception {
|
||||
Pizza p = PizzaFactory.createPizza(type);
|
||||
p.prepare();
|
||||
p.bake();
|
||||
p.cut();
|
||||
return p;
|
||||
}
|
||||
}
|
@ -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 edu.slcc.asdv.caleb.dao.factory_pizza;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class TestPizza {
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
PizzaStore ps = new PizzaStore();
|
||||
ps.orderPizza("cheeze");
|
||||
ps.orderPizza("chicken");
|
||||
ps.orderPizza("veggie");
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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 edu.slcc.asdv.caleb.dao.factory_pizza;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class VeggiePizza implements Pizza {
|
||||
|
||||
@Override
|
||||
public void prepare()
|
||||
{
|
||||
System.out.println("Preparing Veggie Pizza");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bake()
|
||||
{
|
||||
System.out.println("Baking Veggie Pizza");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cut()
|
||||
{
|
||||
System.out.println("Cutting Veggie Pizza");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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 factory_generic_pizza;
|
||||
|
||||
import edu.slcc.asdv.caleb.dao.factory_pizza.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class Pizza<T> {
|
||||
public void prepare(Object t)
|
||||
{
|
||||
System.out.println("preparing " + t.toString() +" Pizza");
|
||||
}
|
||||
|
||||
public void bake(Object t)
|
||||
{
|
||||
System.out.println("baking " + t.toString() +" Pizza");
|
||||
}
|
||||
|
||||
public void cut(Object t)
|
||||
{
|
||||
System.out.println("cutting" + t.toString() +"Pizza");
|
||||
}
|
||||
|
||||
}
|
@ -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 factory_generic_pizza;
|
||||
|
||||
import edu.slcc.asdv.caleb.dao.factory_pizza.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class PizzaFactory {
|
||||
public static <T> Pizza<T> createPizza(T t)
|
||||
{
|
||||
return new Pizza<T>()
|
||||
{
|
||||
public void prepare(T t) {
|
||||
System.out.println("Preparing pizza " + t.toString() + "...");
|
||||
}
|
||||
|
||||
public void bake(T t) {
|
||||
System.out.println("Baking pizza " + t.toString() + "...");
|
||||
}
|
||||
|
||||
public void cut(T t) {
|
||||
System.out.println("Cutting pizza " + t.toString() + "...");
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
@ -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 factory_generic_pizza;
|
||||
|
||||
import edu.slcc.asdv.caleb.dao.factory_pizza.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class PizzaStore {
|
||||
public Pizza orderPizza(String type) throws Exception {
|
||||
Pizza p = PizzaFactory.createPizza(type);
|
||||
p.prepare(type);
|
||||
p.bake(type);
|
||||
p.cut(type);
|
||||
return p;
|
||||
}
|
||||
}
|
@ -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 factory_generic_pizza;
|
||||
|
||||
import edu.slcc.asdv.caleb.dao.factory_pizza.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class TestPizza {
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
PizzaStore ps = new PizzaStore();
|
||||
ps.orderPizza("cheeze");
|
||||
ps.orderPizza("chicken");
|
||||
ps.orderPizza("veggie");
|
||||
}
|
||||
}
|
18
Semester 4/Assignments/DataStructures/nb-configuration.xml
Normal file
18
Semester 4/Assignments/DataStructures/nb-configuration.xml
Normal 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.
|
||||
-->
|
||||
<netbeans.hint.jdkPlatform>JDK_1.8</netbeans.hint.jdkPlatform>
|
||||
</properties>
|
||||
</project-shared-configuration>
|
14
Semester 4/Assignments/DataStructures/pom.xml
Normal file
14
Semester 4/Assignments/DataStructures/pom.xml
Normal 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>edu.slcc.asdv.caleb</groupId>
|
||||
<artifactId>DataStructures</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<exec.mainClass>edu.slcc.asdv.caleb.datastructures.DataStructures</exec.mainClass>
|
||||
</properties>
|
||||
</project>
|
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
*/
|
||||
|
||||
package edu.slcc.asdv.caleb.datastructures;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class DataStructures {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello World!");
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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 edu.slcc.asdv.caleb.datastructures;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public interface OneToMany<One, Many>
|
||||
{
|
||||
/**
|
||||
* Initialization of Ones. The method should be used first before any other
|
||||
* methods
|
||||
*
|
||||
* @param one - the ones ( i.e, countries, or SelectItem or any Object) to
|
||||
* use for initialization
|
||||
* @return true if the initialization succeeded by using the method once,
|
||||
* false when the method is used more than once.
|
||||
*/
|
||||
boolean initializeOne(One... one);
|
||||
|
||||
/**
|
||||
* Initialization of the many for a given one. The method can be used
|
||||
* multiple times after the method initializeOne has succeeded.
|
||||
*
|
||||
* @param one - the one that has the many
|
||||
* @param many - the many which belong to th eone
|
||||
* @throws IllegalArgumentException when the one does not exist (i.e. user's
|
||||
* typing error for the name of one) or when the initialization of the one
|
||||
* has not occurred.
|
||||
*
|
||||
*/
|
||||
void initializeMany(One one, Many... many)
|
||||
throws IllegalArgumentException;
|
||||
|
||||
|
||||
/**
|
||||
* Gets the many of a specific one.
|
||||
*
|
||||
* @param one the one to get its many
|
||||
* @return the many of the parameter one or null if the one does not exist.
|
||||
*/
|
||||
Collection<Many> getMany(One one);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Given a value of the many it gets the one that the many belongs to.
|
||||
*
|
||||
* @param many one of the values of the many
|
||||
* @return the one
|
||||
*/
|
||||
One getOne(Many many);
|
||||
|
||||
/**
|
||||
* Gets a set with all the ones
|
||||
*
|
||||
* @return the set of ones.
|
||||
*/
|
||||
Set<One> getAllOnes();
|
||||
}
|
||||
|
@ -0,0 +1,185 @@
|
||||
package edu.slcc.asdv.caleb.datastructures;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
public class OneToManyFactory {
|
||||
|
||||
/**
|
||||
* Creates an object of type OneToMany
|
||||
*
|
||||
* @param <One> a generic parameter can be any object that denotes a One.
|
||||
* @param <Many> a generic parameter can be any object that denotes a city that belongs to the one generic type.
|
||||
* @return a OneCity object.
|
||||
*/
|
||||
public static <One, Many> //generic types to be used in the method
|
||||
OneToMany<One, Many> //rturn type
|
||||
createOneToMany()
|
||||
{
|
||||
return new OneToMany<One, Many>() {
|
||||
private Map<One, Many> oneToMany = new HashMap();
|
||||
boolean oneInitialized = false;
|
||||
boolean manyInitialized = false;
|
||||
|
||||
@Override
|
||||
public boolean initializeOne(One... one)
|
||||
{
|
||||
if (oneInitialized == false && manyInitialized == false) {
|
||||
for (int i = 0; i < one.length; ++i) {
|
||||
oneToMany.put(one[i], (Many) new Boolean(true));
|
||||
}
|
||||
oneInitialized = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeMany(One one, Many... many)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
if (oneToMany.get(one) == null) { // of the key of the one is null
|
||||
// the method initializekey has not been used
|
||||
throw new IllegalArgumentException(one + " is not valid.");
|
||||
}
|
||||
oneToMany.put(one, (Many) new ArrayList<Many>(Arrays.asList(many)));
|
||||
manyInitialized = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Many> getMany(One one)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
if (oneInitialized == true && manyInitialized == true) {
|
||||
if (oneToMany.get(one) == null) {
|
||||
throw new IllegalArgumentException(one + " is not a valid One");
|
||||
}
|
||||
Collection c1 = (Collection) oneToMany.get(one);
|
||||
return c1;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public One getOne(Many many)
|
||||
{
|
||||
Set< Entry<One, Many>> set = oneToMany.entrySet();
|
||||
for (Map.Entry<One, Many> entry : oneToMany.entrySet()) {
|
||||
One key = (One) entry.getKey();
|
||||
Collection<Many> value = (Collection<Many>) oneToMany.get(key);
|
||||
if (value.contains(many)) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<One> getAllOnes()
|
||||
{
|
||||
return (Set<One>) oneToMany.keySet();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
|
||||
OneToMany cc = OneToManyFactory.createOneToMany();
|
||||
|
||||
try {
|
||||
cc.initializeMany("France", "Paris");
|
||||
} catch (Exception e) {
|
||||
System.err.println(e);
|
||||
}
|
||||
boolean b1 = cc.initializeOne("USA", "Greece");
|
||||
System.out.println(b1);
|
||||
boolean b2 = cc.initializeOne("USA", "Greece");
|
||||
System.out.println(b2);
|
||||
cc.initializeMany("USA", "Lafayette", "New Orleans");
|
||||
cc.initializeMany("Greece", "Athens", "Sparta");
|
||||
Collection<String> cities1 = cc.getMany("USA");
|
||||
System.out.println(cities1);
|
||||
Collection<String> cities2 = cc.getMany("Greece");
|
||||
System.out.println(cities2);
|
||||
System.out.println(cc.getOne("Athens"));
|
||||
System.out.println(cc.getOne("Lafayette"));
|
||||
System.out.println(cc.getOne("France"));
|
||||
try {
|
||||
System.out.println(cc.getMany("Germany"));
|
||||
} catch (Exception e) {
|
||||
System.err.println(e);
|
||||
}
|
||||
|
||||
System.out.println(cc.getAllOnes());
|
||||
System.out.println("----------------------------------------------------------");
|
||||
OneToMany supplierParts = OneToManyFactory.createOneToMany();
|
||||
supplierParts.initializeOne(new Supplier("s1"), new Supplier("s2"));
|
||||
Supplier s1 = new Supplier("s1");
|
||||
Supplier s2 = new Supplier("s2");
|
||||
supplierParts.initializeOne(s1, s2);
|
||||
Part p1 = new Part("p1");
|
||||
Part p2 = new Part("p2");
|
||||
Part p3 = new Part("p3");
|
||||
Part p4 = new Part("p4");
|
||||
supplierParts.initializeMany(s1, p1, p2);
|
||||
supplierParts.initializeMany(s2, p3, p4);
|
||||
}
|
||||
}
|
||||
class Supplier {
|
||||
|
||||
public Supplier(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
private String name;
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Supplier{" + "name=" + name + '}';
|
||||
}
|
||||
}
|
||||
|
||||
class Part {
|
||||
|
||||
public Part(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
private String name;
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Part{" + "name=" + name + '}';
|
||||
}
|
||||
}
|
14
Semester 4/Assignments/ProjectTrees_CalebFontenot/pom.xml
Normal file
14
Semester 4/Assignments/ProjectTrees_CalebFontenot/pom.xml
Normal 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>edu.slcc.asdv.caleb</groupId>
|
||||
<artifactId>ProjectTrees_CalebFontenot</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>20</maven.compiler.source>
|
||||
<maven.compiler.target>20</maven.compiler.target>
|
||||
<exec.mainClass>edu.slcc.asdv.caleb.projecttrees_calebfontenot.ProjectTrees_CalebFontenot</exec.mainClass>
|
||||
</properties>
|
||||
</project>
|
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
*/
|
||||
|
||||
package edu.slcc.asdv.caleb.projecttrees_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class ProjectTrees_CalebFontenot {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello World!");
|
||||
}
|
||||
}
|
@ -0,0 +1,184 @@
|
||||
/*
|
||||
* 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 edu.slcc.asdv.caleb.projecttrees_calebfontenot;
|
||||
|
||||
import java.util.ListIterator;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class TreeASDV<T extends Comparable> {
|
||||
|
||||
private Node<T> root;
|
||||
|
||||
class Node<T> {
|
||||
|
||||
T data;
|
||||
Node<T> leftChild;
|
||||
Node<T> rightChild;
|
||||
}
|
||||
|
||||
public boolean insert(T t)
|
||||
{
|
||||
Node<T> currentNode = root;
|
||||
Node<T> trailCurrent = root;
|
||||
Node<T> newNode = new Node<T>();
|
||||
newNode.data = t;
|
||||
System.out.println(t);
|
||||
|
||||
if (this.root == null) {
|
||||
this.root = newNode;
|
||||
return true;
|
||||
}
|
||||
|
||||
while (currentNode != null) {
|
||||
trailCurrent = currentNode;
|
||||
if (t.compareTo(currentNode.data) >= 0) {
|
||||
currentNode = currentNode.rightChild;
|
||||
} else {
|
||||
currentNode = currentNode.leftChild;
|
||||
}
|
||||
if (t.compareTo(trailCurrent.data) >= 0) { // Make the node a right child.
|
||||
trailCurrent.rightChild = newNode;
|
||||
} else { // Make the node a left child.
|
||||
trailCurrent.leftChild = newNode;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void inOrder(Node<T> p)
|
||||
{
|
||||
if (p == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
inOrder(p.leftChild);
|
||||
System.out.print(p.data + " ");
|
||||
inOrder(p.rightChild);
|
||||
}
|
||||
|
||||
public void inOrder()
|
||||
{
|
||||
inOrder(this.root);
|
||||
}
|
||||
|
||||
public Node<T> findNode(T t)
|
||||
{
|
||||
Node<T> currentNode = root;
|
||||
while (currentNode != null) {
|
||||
if (t.compareTo(currentNode.data) == 0) {
|
||||
return currentNode;
|
||||
} else if (t.compareTo(currentNode.data) > 0) {
|
||||
currentNode = currentNode.rightChild;
|
||||
} else {
|
||||
currentNode = currentNode.leftChild;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean remove(T t)
|
||||
{
|
||||
// case: no children
|
||||
if (root.leftChild == null & root.rightChild == null) {
|
||||
root = null;
|
||||
return true;
|
||||
}
|
||||
Node<T> current = this.root;
|
||||
Node<T> currentParent = this.root;
|
||||
|
||||
while (current.data.equals(t)) {
|
||||
if (t.compareTo(current.data) == 0) {
|
||||
break;
|
||||
}
|
||||
else if (t.compareTo(currentParent.data) > 0) {
|
||||
currentParent = current;
|
||||
current = current.rightChild;
|
||||
} else {
|
||||
currentParent = current;
|
||||
current = current.leftChild;
|
||||
}
|
||||
}
|
||||
if (current == null) {
|
||||
return false;
|
||||
}
|
||||
if (current.data.compareTo(currentParent.data) <= 0) {
|
||||
currentParent.leftChild = null;
|
||||
} else {
|
||||
currentParent.rightChild = null;
|
||||
}
|
||||
// case: single child
|
||||
if (current.leftChild == null || current.rightChild == null) {
|
||||
// if the current is the right child of its parent
|
||||
if (current.data.compareTo(t) > 0) {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
// case: two children
|
||||
else {
|
||||
// take a left
|
||||
Node<T> p = current;
|
||||
p = current.leftChild;
|
||||
Node<T> pTrailParent = p;
|
||||
Node<T> pTrail = p;
|
||||
while (p != null) { // keep going right
|
||||
pTrailParent = pTrail;
|
||||
pTrail = p;
|
||||
p = p.rightChild;
|
||||
}
|
||||
// swap the data of pTrail with the current
|
||||
current.data = pTrail.data;
|
||||
if (pTrail == pTrailParent) {
|
||||
pTrailParent.leftChild = pTrail.leftChild;
|
||||
} else {
|
||||
pTrailParent.rightChild = pTrail.leftChild;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public ListIterator<T> listIterator(){
|
||||
ListIterator it = new ListIterator<T>();
|
||||
return null;
|
||||
}
|
||||
public void breathFirst() {
|
||||
Stack<Node<T>> stack = new Stack();
|
||||
Node<T> p = root;
|
||||
System.out.println(p.data + " ");
|
||||
stack.push(p.rightChild);
|
||||
|
||||
while (stack.empty() == false) {
|
||||
// go to the left
|
||||
p = p.leftChild;
|
||||
if (p != null) {
|
||||
System.out.println(p.data);
|
||||
}
|
||||
Node<T> rightChild = stack.pop();
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
TreeASDV tree = new TreeASDV();
|
||||
tree.insert(100);
|
||||
tree.insert(80);
|
||||
tree.insert(90);
|
||||
tree.insert(95);
|
||||
tree.insert(93);
|
||||
tree.insert(70);
|
||||
tree.inOrder();
|
||||
tree.remove(100);
|
||||
System.out.println();
|
||||
tree.inOrder();
|
||||
}
|
||||
}
|
14
Semester 4/EnumDemo/pom.xml
Normal file
14
Semester 4/EnumDemo/pom.xml
Normal 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>edu.slcc.asdv.caleb</groupId>
|
||||
<artifactId>EnumDemo</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>20</maven.compiler.source>
|
||||
<maven.compiler.target>20</maven.compiler.target>
|
||||
<exec.mainClass>edu.slcc.asdv.caleb.enumdemo.EnumDemo</exec.mainClass>
|
||||
</properties>
|
||||
</project>
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
*/
|
||||
|
||||
package edu.slcc.asdv.caleb.enumdemo;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class EnumDemo {
|
||||
|
||||
public enum Day {
|
||||
SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
|
||||
THURSDAY, FRIDAY, SATURDAY
|
||||
}
|
||||
Day day;
|
||||
|
||||
public EnumDemo(Day day)
|
||||
{
|
||||
this.day = day;
|
||||
}
|
||||
|
||||
|
||||
public void tellItLikeItIs() {
|
||||
switch (day) {
|
||||
case MONDAY:
|
||||
System.out.println("Mondays are bad.");
|
||||
break;
|
||||
|
||||
case FRIDAY:
|
||||
System.out.println("Fridays are better.");
|
||||
break;
|
||||
|
||||
case SATURDAY: case SUNDAY:
|
||||
System.out.println("Weekends are best.");
|
||||
break;
|
||||
|
||||
default:
|
||||
System.out.println("Midweek days are so-so.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
public static void main(String[] args)
|
||||
{
|
||||
EnumDemo day1 = new EnumDemo(Day.MONDAY);
|
||||
day1.tellItLikeItIs();
|
||||
EnumDemo day2 = new EnumDemo(Day.TUESDAY);
|
||||
day2.tellItLikeItIs();
|
||||
EnumDemo day3 = new EnumDemo(Day.WEDNESDAY);
|
||||
day3.tellItLikeItIs();
|
||||
EnumDemo day4 = new EnumDemo(Day.THURSDAY);
|
||||
day4.tellItLikeItIs();
|
||||
EnumDemo day5 = new EnumDemo(Day.FRIDAY);
|
||||
day5.tellItLikeItIs();
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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 edu.slcc.asdv.caleb.enumdemo;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public enum Planet {
|
||||
MERCURY(3.303e+23, 2.4397e6),
|
||||
VENUS(4.869e+24, 6.0518e6),
|
||||
EARTH(5.976e+24, 6.37814e6),
|
||||
MARS(6.421e+23, 3.3972e6),
|
||||
JUPITER(1.9e+27, 7.1492e7),
|
||||
SATURN(5.688e+26, 6.0268e7),
|
||||
URANUS(8.686e+25, 2.5559e7),
|
||||
NEPTUNE(1.024e+26, 2.4746e7);
|
||||
|
||||
private final double mass; // in kilograms
|
||||
private final double radius; // in meters
|
||||
|
||||
Planet(double mass, double radius)
|
||||
{
|
||||
this.mass = mass;
|
||||
this.radius = radius;
|
||||
}
|
||||
|
||||
private double mass()
|
||||
{
|
||||
return mass;
|
||||
}
|
||||
|
||||
private double radius()
|
||||
{
|
||||
return radius;
|
||||
}
|
||||
|
||||
// universal gravitational constant (m3 kg-1 s-2)
|
||||
public static final double G = 6.67300E-11;
|
||||
|
||||
double surfaceGravity()
|
||||
{
|
||||
return G * mass / (radius * radius);
|
||||
}
|
||||
|
||||
double surfaceWeight(double otherMass)
|
||||
{
|
||||
return otherMass * surfaceGravity();
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
args = new String[1];
|
||||
args[0] = "175";
|
||||
if (args.length != 1) {
|
||||
System.err.println("Usage: java Planet <earth_weight>");
|
||||
System.exit(-1);
|
||||
}
|
||||
double earthWeight = Double.parseDouble(args[0]);
|
||||
double mass = earthWeight / EARTH.surfaceGravity();
|
||||
for (Planet p : Planet.values()) {
|
||||
System.out.printf("Your weight on %s is %f%n",
|
||||
p, p.surfaceWeight(mass));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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 edu.slcc.asdv.caleb.enumdemo;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class TestPlanet {
|
||||
Planet planet;
|
||||
|
||||
public TestPlanet(Planet planet) {
|
||||
this.planet = planet;
|
||||
}
|
||||
public static void main(String[] args)
|
||||
{
|
||||
//TestPlanet testPlanet = new Planet.valueOf("EARTH");
|
||||
// System.out.println(testPlanet.planet.EARTH);
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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 singlenton;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class SingletonFlight {
|
||||
|
||||
private ArrayList<String> seats;
|
||||
private static SingletonFlight instance;
|
||||
|
||||
private SingletonFlight() {
|
||||
seats = new ArrayList<String>(4);
|
||||
|
||||
}
|
||||
public static SingletonFlight getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new SingletonFlight();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public boolean bookFlight(String nameOfPassenger) {
|
||||
if (seats.size() > 4) {
|
||||
System.out.println("Flight full!");
|
||||
return false;
|
||||
} else {
|
||||
System.out.println("Added " + nameOfPassenger + " now has their seat booked.");
|
||||
seats.add(nameOfPassenger);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public static void main(String[] args)
|
||||
{
|
||||
SingletonFlight passenger1 = SingletonFlight.getInstance();
|
||||
SingletonFlight passenger2 = SingletonFlight.getInstance();
|
||||
SingletonFlight passenger3 = SingletonFlight.getInstance();
|
||||
SingletonFlight passenger4 = SingletonFlight.getInstance();
|
||||
|
||||
passenger1.bookFlight("John Wayne");
|
||||
passenger2.bookFlight("John Wayne Jr.");
|
||||
passenger3.bookFlight("Joanne Wayne");
|
||||
passenger4.bookFlight("Joseph Wayne");
|
||||
passenger4.bookFlight("Jessica Wayne");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user