Markou why must you make agonizing assignments

master
Caleb Fontenot 2023-10-18 23:12:48 +07:00
parent f9babdde19
commit 95546d4a94
74 changed files with 3581 additions and 22 deletions

1
.gitignore vendored

@ -181,3 +181,4 @@
/Semester 3/Assignments/DBConnectionTest/target/
/Semester 3/Assignments/mavenproject1/target/
/Semester 3/Assignments/JavaFXBallsWithComparator/target/
/Semester 3/Assignments/MP4_CalebFontenot/target/

@ -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>MP4_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>edu.slcc.asdv.caleb.mp4_calebfontenot.MP4_CalebFontenot</exec.mainClass>
</properties>
</project>

@ -0,0 +1,975 @@
/*
* 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.mp4_calebfontenot;
/**
*
* @author caleb
*/
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.function.Consumer;
/**
*
* @author ASDV2
*/
public class ArrayListASDV<E>
implements Serializable, Cloneable, List<E> {
private E[] list;
private int index;//the index to add at ( length of array)
//private Class<E> type;
/**
* Constructs an empty list with an initial capacity of three.
*
*/
public ArrayListASDV() {
list = (E[]) new Object[3];
index = 0;
}
/**
* Constructs an empty list with the specified initial capacity.
*
* @param initialCapacity - the initial capacity of the list
* @throws IllegalArgumentException - if the specified initial capacity is negative
*/
public ArrayListASDV(int initialCapacity) {
if (initialCapacity < 0) {
throw new IllegalArgumentException("initialCapacity id negative: " + initialCapacity);
}
list = (E[]) new Object[initialCapacity];
index = 0;
}
/**
* Double the size of the current list and copies to it the old list
*
* @return the new array.
*/
private E[] doubleSizeOfList() {
list = this.toArray((E[]) new Object[list.length + list.length]);
return this.list;
}
/**
* Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator.
*
* @param c - the collection whose elements are to be placed into this
* @throws NullPointerException - if the specified collection is null
*
*
*/
public ArrayListASDV(Collection<? extends E> c) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
/**
* Returns true if this collection changed as a result of the call. false if this collection does not permit duplicates and already contains the specified element.
*
* @param e - element whose presence in this collection is to be ensured
*
* @return true if this collection changed as a result of the call
* @throws ClassCastException - if the class of the specified element prevents it from being added to this collection
* @throws NullPointerException - if the specified element is null and this collection does not permit null elements
* @throws IllegalArgumentException - if some property of the element prevents it from being added to this collection
*/
@Override
public boolean add(E e) {
if (e == null) {
throw new NullPointerException("null parameter");
}
list[index++] = e;
if (index >= list.length * 0.75) {
doubleSizeOfList();
}
return true;
}
/**
* Returns the number of elements in this list.
*
* @return the number of elements in this list.
*/
@Override
public int size() {
return index;
}
@Override
public String toString() {
String s = "ArrayListASDV[";
for (int i = 0; i < index; ++i) {
s += list[i] + " ";
}
s += "]";
return s;
}
/**
* Returns true if this list contains no elements.
*
* @return true if this list contains no elements
*
*/
@Override
public boolean isEmpty() {
return this.index == 0;
}
/**
* Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that (o==null ? e==null : o.equals(e)).
*
* @param o - element whose presence in this list is to be tested
*
* @return true if this list contains the specified element
*
*/
public boolean contains(Object o) {
if (o == null) {
return false;
}
for (int i = 0; i < this.index; i++) {
if (o.equals(this.list[i])) {
return true;
}
}
return false;
}
/**
* Returns an array containing all of the elements in this list in proper sequence (from first to last element). The returned array will be "safe" in that no references to it are maintained by this list. (In other words, this method must allocate a new array). The caller is thus free to modify the returned array. This method acts as bridge between array-based and collection-based APIs. Returns: an array containing all of the elements in this list in proper sequence
*
* @return an array containing all of the elements in this list in proper sequence
*/
@Override
public Object[] toArray() {
Object[] returnArray = new Object[index];
for (int i = 0; i < index; ++i) {
Object objCopy = list[i];
returnArray[i] = objCopy;
}
return returnArray;
}
/**
* Removes the first occurrence of the specified element from this list, if it is present. If the list does not contain the element, it is unchanged. More formally, removes the element with the lowest index i such that (o==null ? get(i)==null : o.equals(get(i))) (if such an element exists). Returns true if this list contained the specified element (or equivalently, if this list changed as a result of the call).
*
* @param o - element to be removed from this list, if present
* @return true if this list contained the specified element
*/
@Override
public boolean remove(Object o) {
if (o == null) {
return false;
}
Object[] newArray = new Object[index];
int i = 0;
for (Object arrayElement : list) {
try {
if (!arrayElement.equals(o)) {
newArray[i] = arrayElement;
}
if ((index - 1) > i) {
++i;
}
} catch (NullPointerException ex) {
continue;
}
}
--index;
list = (E[]) newArray;
return true;
}
/**
* Removes all of the elements from this list. The list will be empty after this call returns. Note: Traverse the array and set all of its elements to null. Set its index to zero.
*/
@Override
public void clear() {
for (int i = 0; i < list.length; ++i) {
list[i] = null;
}
index = 0;
}
/**
* Returns the element at the specified position in this list.
*
* @param index of the element to return
* @return the element at the specified position in this list
* @throws IndexOutOfBoundsException - if the index is out of range (index GE 0 || index GE size())
*/
@Override
public E get(int index) {
return list[index];
}
/**
* Replaces the element at the specified position in this list with the specified element.
*
* @param index - index of the element to replace
* @param element - element to be stored at the specified position
* @return the element previously at the specified position
* @throws IndexOutOfBoundsException - if the index is out of range (index GE 0 || index GE size())
*/
@Override
public E set(int index, E element) {
return list[index] = element;
}
/**
* Inserts the specified element at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
*
* @param index - index at which the specified element is to be inserted element
* @param - element to be inserted
* @throws NullPointerException - if the specified element is null and this collection does not permit null elements
* @throws IndexOutOfBoundsException - if the index is out of range (index GE 0 || index GE size())
*/
public void add(int index, E element) {
if (element == null) {
throw new NullPointerException("cant add null");
}
if (index > this.index || index < 0) {
throw new IndexOutOfBoundsException("cant add at this index");
}
// Check if the list needs to be resized
if (this.index >= list.length) {
doubleSizeOfList();
}
// Shift elements to the right to make space for the new element
for (int i = this.index; i > index; i--) {
list[i] = list[i - 1];
}
// Insert the new element at the specified index
list[index] = element;
this.index++;
}
/**
* Removes the element at the specified position in this list. Shifts any subsequent elements to the left (subtracts one from their indices).
*
* @param index - the index of the element to be removed
* @return the element that was removed from the list
* @throws IndexOutOfBoundsException - if the index is out of range (index GE 0 || index GE size())
*/
public E remove(int index) {
Object removedObject = new Object();
if (index < 0 || index >= this.index) {
throw new IndexOutOfBoundsException("Index " + index + " out of bounds");
}
Object[] newArray = new Object[index];
int j = 0;
for (int i = 0; i < index; ++i) {
try {
if (i != index) {
newArray[j] = list[i];
} else {
removedObject = list[i];
}
if ((index - 1) > j) {
++j;
}
} catch (NullPointerException ex) {
continue;
}
}
--this.index;
list = (E[]) newArray;
return (E) removedObject;
}
/**
* Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the lowest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index. Parameters:
*
* @param o - element to search for
* @return the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element
*/
@Override
public int indexOf(Object o) {
for (int i = 0; i < index - 1; i++) {
if (list[i].equals(o)) {
return i;
}
}
return -1;
}
/**
* Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the highest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index. Parameters:
*
* @param o - element to search for
* @return the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element
*/
@Override
public int lastIndexOf(Object o) {
for (int i = list.length - 1; i >= 0; i--) {
if (list[i] != null && list[i].equals(o)) {
return i;
}
}
return -1;
}
/**
* Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive. (If fromIndex and toIndex are equal, the returned list is empty.) The returned list is backed by this list, so non-structural changes in the returned list are reflected in this list, and vice-versa. The returned list supports all of the optional list operations. This method eliminates the need for explicit range operations (of the sort that commonly exist for arrays). Any operation that expects a list can be used as a range operation by passing a subList view instead of a whole list. For example, the following idiom removes a range of elements from a list: list.subList(from, to).clear();
*
* Similar idioms may be constructed for ArrayList.indexOf(Object) and ArrayList.lastIndexOf(Object), and all of the algorithms in the Collections class can be applied to a subList. The semantics of the list returned by this method become undefined if the backing list (i.e., this list) is structurally modified in any way other than via the returned list. (Structural modifications are those that change the size of this list, or otherwise perturb it in such a fashion that iterations in progress may yield incorrect results.)
*
* @param fromIndex - low endpoint (inclusive) of the subList
* @param toIndex - high endpoint (exclusive) of the subList
* @return a view of the specified range within this list
* @throws IndexOutOfBoundsException - for an illegal endpoint index value (fromIndex LE 0 || toIndex > size || fromIndex > toIndex)
* @throws IllegalArgumentException - if the endpoint indices are out of order (fromIndex > toIndex)
*/
@Override
public List<E> subList(int fromIndex, int toIndex) {
if (fromIndex < 0 || toIndex > size() || fromIndex > toIndex) {
throw new IndexOutOfBoundsException();
}
List<E> sublist = new ArrayListASDV<>();
for (int i = fromIndex; i < toIndex; i++) {
sublist.add(get(i));
}
return sublist;
}
/**
* Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array. If the list fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this list. If the list fits in the specified array with room to spare (i.e., the array has more elements than the list), the element in the array immediately following the end of the collection is set to null. (This is useful in determining the length of the list only if the caller knows that the list does not contain any null elements.)
*
* @param a - the array into which the elements of the list are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
* @return an array containing the elements of the list
* @throws ArrayStoreException - if the runtime type of the specified array is not a supertype of the runtime type of every element in this list
* @throws NullPointerException - if the specified array is null
*/
@Override
public <T> T[] toArray(T[] a) {
Class<?> clazz = a.getClass();
//>length of a is too small
if (a.length < index) // Make a new array of a's runtime type
{
return (T[]) Arrays.copyOf(this.list,
index,
a.getClass());
}
//>length of a is good
System.arraycopy(this.list, 0, a, 0, index);
//>length of a is greater than this list set nulls
if (a.length > index) {
for (int i = index; i < a.length; ++i) {
a[i] = null;
}
}
return a;
}
@Override
public Iterator<E> iterator() {
Iterator<E> it = new Iterator<E>() {
int index = 0;
//E[] list = (E[]) new Object[3];
@Override
public boolean hasNext() {
if (index == list.length) {
return false;
}
return true;
}
@Override
public E next() {
return list[index++];
}
@Override
public void remove() {
if (index < 1) {
Object[] newList = new Object[--index];
for (int i = 0; i < index; i++) {
newList[i] = list[i];
}
list = (E[]) newList;
}
}
/**
* Performs the given action for each remaining element until all elements have been processed or the action throws an exception- Actions are performed in the order of iteration, if that order is specified- Exceptions thrown by the action are relayed to the caller.
*
*
* @throws NullPointerException - if the specified action is null
*/
@Override
public void forEachRemaining(Consumer<? super E> action) {
if (action == null) {
throw new NullPointerException("Action is Null");
}
while (hasNext()) {
action.accept(next());
}
}
};
return (Iterator<E>) it;
}
;
/**
* Returns a list iterator over the elements in this list (in proper sequence). The returned list iterator is fail-fast.
*
*
* @return a list iterator over the elements in this list (in proper sequence
*/
@Override
public ListIterator<E> listIterator() {
return listIterator(0);
}
@Override
public ListIterator<E> listIterator(int index) {
ListIterator<E> it = new ListIterator<E>() {
//E[] list = (E[]) new Object[3];
int index;
/**
* Returns true if this list iterator has more elements when traversing the list in the forward direction. (In other words, returns true if ListIterator.next would return an element rather than throwing an exception.)
*
* @return true if the list iterator has more elements when traversing the list in the forward direction
*/
@Override
public boolean hasNext() {
return next() != null;
}
/**
* Returns the next element in the list and advances the cursor position. This method may be called repeatedly to iterate through the list, or intermixed with calls to ListIterator.previous to go back and forth. (Note that alternating calls to next and previous will return the same element repeatedly.)
*
* @return the next element in the list
* @throws NoSuchElementException - if the iteration has no next element
*/
@Override
public E next() throws NoSuchElementException {
if (index > list.length) {
throw new NoSuchElementException();
}
System.out.println("List iterator next() "+ list[index]);
return list[index++];
}
@Override
public boolean hasPrevious() {
return index > 0;
}
@Override
public E previous() {
return list[--index];
}
/**
* Returns the index of the element that would be returned by a subsequent call to next(). (Returns list size if the list iterator is at the end of the list.)
*
* @return the index of the element that would be returned by a subsequent call to next, or list size if the list iterator is at the end of the list
*/
@Override
public int nextIndex() {
return index + 1;
}
/**
* Returns the index of the element that would be returned by a subsequent call to previous(). (Returns -1 if the list iterator is at the beginning of the list.)
*
* @return the index of the element that would be returned by a subsequent call to previous, or -1 if the list iterator is at the beginning of the list
*/
@Override
public int previousIndex() {
return index - 1;
}
/**
* Performs the given action for each remaining element until all elements have been processed or the action throws an exception- Actions are performed in the order of iteration, if that order is specified- Exceptions thrown by the action are relayed to the caller.
*
*
* @throws NullPointerException - if the specified action is null
*/
@Override
public void forEachRemaining(Consumer<? super E> action) {
if (action == null) {
throw new NullPointerException("Action is Null");
}
while (hasNext()) {
action.accept(next());
}
}
@Override
public void remove() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void set(E e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void add(E e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
};
return it;
}
/**
*
* Returns true if this collection contains all of the elements in the specified collection.
*
* Parameters: c - collection to be checked for containment in this collection Returns: true if this collection contains all of the elements in the specified collection Throws: ClassCastException - if the types of one or more elements in the specified collection are incompatible with this collection (optional) NullPointerException - if the specified collection contains one or more null elements and this collection does not permit null elements (optional), or if the specified collection is null.
*
* @param c - collection to be checked for containment in this collection
* @return true if this collection contains all of the elements in the specified collection.
* @throws ClassCastException - if the types of one or more elements in the specified collection are incompatible with this collection
*/
@Override
public boolean containsAll(Collection<?> c) {
for (Object e : c) {
if (!contains(e)) {
return false;
}
}
return true;
}
@Override
public boolean addAll(Collection<? extends E> c) {
boolean changed = false;
for (E e : c) {
if (add(e)) {
changed = true;
}
}
return changed;
}
@Override
public boolean addAll(int index, Collection<? extends E> c) {
boolean changed = false;
for (E e : c) {
add(index++, e);
changed = true;
}
return changed;
}
/**
* Removes all of this collection's elements that are also contained in the specified collection (optional operation). After this call returns, this collection will contain no elements in common with the specified collection.
*
* Parameters: c - collection containing elements to be removed from this collection Returns: true if this collection changed as a result of the call Throws: UnsupportedOperationException - if the removeAll method is not supported by this collection ClassCastException - if the types of one or more elements in this collection are incompatible with the specified collection (optional) NullPointerException - if this collection contains one or more null elements and the specified collection does not support null elements (optional), or if the specified collection is null
*
* @param c - collection containing elements to be removed from this collection
* @return true if this collection changed as a result of the call
* @throws ClassCastException - if the types of one or more elements in this collection are incompatible with the specified collection
*/
@Override
public boolean removeAll(Collection<?> c) {
Objects.requireNonNull(c);
List<E> elToKeep = new ArrayList<>(this);
elToKeep.removeAll(c);
elToKeep.removeIf(Objects::isNull);
clear();
addAll(elToKeep);
return !elToKeep.isEmpty();
}
/**
* Retains only the elements in this collection that are contained in the specified collection (optional operation). In other words, removes from this collection all of its elements that are not contained in the specified collection.
*
*
* @param c - collection containing elements to be retained in this collection
* @return true if this collection changed as a result of the call
* @throws ClassCastException - if the types of one or more elements in this collection are incompatible with the specified collection (optional)
*/
@Override
public boolean retainAll(Collection<?> c) {
Objects.requireNonNull(c);
List<E> elToKeep = new ArrayList<>();
for (E element : this) {
if (c.contains(element)) {
elToKeep.add(element);
}
}
elToKeep.removeIf(Objects::isNull);
clear();
addAll(elToKeep);
return size() != elToKeep.size();
}
public static void main(String[] args)
throws ClassNotFoundException, InterruptedException {
ArrayListASDV<Integer> aaa = new ArrayListASDV();
aaa.add(1);
aaa.add(2);
aaa.add(3);
aaa.add(4);
ArrayListASDV<Integer> list1 = new ArrayListASDV();
ArrayListASDV<String> list2 = new ArrayListASDV(4);
ArrayListASDV<A1> list3 = new ArrayListASDV(4);
System.out.println("------------------------------ ");
System.out.println("test add");
list1.add(10);
list1.add(20);
list3.add(new A1(-1));
list3.add(new A1(-2));
Integer[] b
= {
2, 3
};
list1.toArray(b);
list2.add("a");
try {
list2.add(null);
} catch (NullPointerException e) {
System.err.println(e);
};
list2.add("b");
list2.add("c");
list2.add("d");
System.out.println("------------------------------ ");
System.out.println("test toString");
System.out.println(list1);
System.out.println(list2);
System.out.println(list3);
System.out.println("------------------------------ ");
System.out.println("test contains");
System.out.println("contains E");
System.out.println("contains c: " + list2.contains("c"));
System.out.println("contains null: " + list2.contains(null));
System.out.println("contains k: " + list2.contains('k'));
System.out.println(list2);
System.out.println("contains A(-1): " + list3.contains(new A1(-1)));
System.out.println("contains A(-3): " + list3.contains(new A1(-3)));
System.out.println("------------------------------ ");
System.out.print("test toArray(): ");
Object[] ar = list2.toArray();
System.out.print("[ ");
for (int i = 0; i < ar.length; ++i) {
System.out.print(ar[i] + " ");
}
System.out.println(" ] ");
System.out.println("\n---------------------------------------");
System.out.println("test clear()");
list2.clear();
System.out.println(list2);
System.out.println("\n---------------------------------------");
System.out.println("test size");
System.out.println(list2.size());
System.out.println("\n---------------------------------------");
System.out.println("test add(index, element)");
for (char a = 'Z'; a >= 'A'; --a) {
System.out.println("array size: " + list2.size());
list2.add(0, "" + a);
}
System.out.println(list2);
list2.add(26, "z");
System.out.println(list2);
list2.add(list2.size() - 2, "y");
System.out.println(list2);
System.out.println("\n---------------------------------------");
System.out.println("test remove(index)");
Object o = list2.remove(27);
System.out.println(o);
System.out.println(list2);
try {
list2.remove(30);
} catch (IndexOutOfBoundsException e) {
System.err.println(e);
}
System.out.println("\n---------------------------------------");
System.out.println("test remove(Object)");
list2.remove("y");
System.out.println(list2);
System.out.println(list2.remove("not in there"));
System.out.println("\n---------------------------------------");
System.out.println("test set(index, Object)");
list2.set(0, "0");
list2.set(25, "25");
System.out.println(list2);
System.out.println("\n---------------------------------------");
System.out.println("test indexOf()");
System.out.println(list2.indexOf("0"));
System.out.println(list2.indexOf("B"));
System.out.println(list2.indexOf("25"));
System.out.println(list2.indexOf("Y"));
System.out.println(list2.indexOf("not there"));
System.out.println("\n---------------------------------------");
System.out.println("test lastIndexOf()");
list2.add(10, "0");
System.out.println(list2.indexOf("0"));
System.out.println(list2.lastIndexOf("0"));
System.out.println(list2.indexOf("not there"));
System.out.println(list2);
System.out.println("\n---------------------------------------");
System.out.println("test sublist(from, to)");
List<String> l1 = list2.subList(1, 10);
ArrayListASDV<String> l2 = (ArrayListASDV<String>) list2.subList(11, 26);
System.out.println(l1);
System.out.println(l2);
List<String> l3 = l2.subList(11, 11);
System.out.println(l3);
try {
l2.subList(12, 11);
} catch (Exception e) {
System.err.println(e);
}
System.out.println("\n---------------------------------------");
System.out.println("test toArray()");
Object[] ar1 = l2.toArray();
for (Object obj : ar1) {
System.out.print(obj + " ");
}
System.out.println("\n---------------------------------------");
System.out.println("test toArray(T[] a) small size a");
ArrayListASDV<Integer> listX = new ArrayListASDV();
listX.add(10);
listX.add(20);
Integer[] a1
= {
1
};
ar = listX.toArray(ar);
for (int i = 0; i < ar.length; ++i) {
System.out.println(ar[i]);
}
System.out.println("\n---------------------------------------");
System.out.println("test toArray(T[] a) Big size a");
ArrayListASDV<A1> listA1 = new ArrayListASDV();
listA1.add(new A1(100));
A1[] a11
= {
new A1(-1), new A1(-2), new A1(3)
};
listA1.toArray(a11);
for (int i = 0; i < a11.length; ++i) {
System.out.println(a11[i]);
}
System.out.println("");
System.out.println("\n---------------------------------------");
System.out.println("test Iterator()");
System.out.println(list2);
Iterator<String> it = list2.iterator();
while (it.hasNext()) {
System.out.print(it.next() + " ");
}
System.out.println("");
System.out.println("\n---------------------------------------");
System.out.println("test ListIterator1()");
ArrayListASDV<Integer> li3 = new ArrayListASDV();
li3.add(10);
li3.add(20);
li3.add(30);
li3.add(40);
System.out.println(li3);
ListIterator<Integer> li = li3.listIterator(2);
while (li.hasNext()) {
System.out.print("\tnext index: " + li.nextIndex());
System.out.print("\tprevious index: " + li.previousIndex());
System.out.print("\t" + li.next());
}
System.out.println("");
while (li.hasPrevious()) {
System.out.print("\tnext index: " + li.nextIndex());
System.out.print("\tprevious index: " + li.previousIndex());
System.out.print("\t" + li.previous());
}
System.out.println("");
System.out.println("next index: " + li.nextIndex());
System.out.println("previous index: " + li.previousIndex());
System.out.println("\n--------------------------removeAll-------------");
System.out.println("test forEachRemaining()");
System.out.println(li.next());
li.forEachRemaining(new Consumer<Integer>() {
@Override
public void accept(Integer t) {
System.out.print(t + 1 + " ");
}
});
System.out.println("\n---------------------------------------");
System.out.println("test containsAll(Collection)");
List<Integer> ar33 = Arrays.asList(new Integer[]{
10, 20
});
System.out.println(li3.containsAll(ar33));
ar33 = Arrays.asList(new Integer[]{
10, -1
});
System.out.println(li3.containsAll(ar33));
System.out.println("\n---------------------------------------");
System.out.println("test removeAll(Collection)");
li3.add(10);
li3.add(11);
li3.add(10);
System.out.println(li3);
ar33 = Arrays.asList(new Integer[]{
10
});
System.out.println(li3.removeAll(ar33));
System.out.println(li3);
List<Object> oar = Arrays.asList(new Object[]{
3.3, 40, "abc"
});
try {
li3.removeAll(oar);
} catch (ClassCastException e) {
Thread.sleep(100);
System.err.println(e);
}
System.out.println(li3);
List<A1> sar = Arrays.asList(new A1[]{
new A1(999)
});
try {
li3.removeAll(sar);
} catch (ClassCastException e) {
Thread.sleep(100);
System.err.println(e);
}
System.out.println(li3);
System.out.println("\n---------------------------------------");
System.out.println("test retainAll(Collection)");
ar33 = Arrays.asList(new Integer[]{
30
});
li3.retainAll(ar33);
System.out.println(li3);
System.out.println("\n---------------------------------------");
System.out.println("test addAll(Collection)");
ar33 = Arrays.asList(new Integer[]{
1, 2, 3, 4
});
li3.addAll(ar33);
System.out.println(li3);
System.out.println("\n---------------------------------------");
System.out.println("test addAll(index, Collection)");
ar33 = Arrays.asList(new Integer[]{
100, 200, 300
});
li3.addAll(2, ar33);
System.out.println(li3);
}
}
class A1 implements Consumer<A1> {
int x;
public A1(int x) {
this.x = x;
}
@Override
public String toString() {
return "A1{" + "x=" + x + '}';
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final A1 other = (A1) obj;
if (this.x != other.x) {
return false;
}
return true;
}
@Override
public void accept(A1 t) {
System.out.println(t.x * t.x);
}
}

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

@ -0,0 +1,72 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>A1.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; font-weight: bold}
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
.string {color: #6a8759}
.number {color: #6897bb}
.ST1 {color: #9876aa}
.ST2 {color: #ffc66d}
.comment {color: #808080}
.whitespace {color: #505050}
.ST3 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
.ST4 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
.ST0 {color: #287bde}
.literal {color: #cc7832}
.ST5 {font-family: monospace; font-weight: bold; font-style: italic}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/JavaFXBallsWithComparator/src/main/java/edu/slcc/asdv/caleb/javafxballswithcomparator/A1.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> edu.slcc.asdv.caleb.javafxballswithcomparator;
<span class="literal">import</span> java.util.Arrays;
<span class="literal">import</span> java.util.Collections;
<span class="literal">import</span> java.util.List;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> A1 <span class="literal">implements</span> Comparable&lt;A1&gt; {
<span class="literal">int</span> <span class="ST1">x</span>;
<span class="literal">public</span> A1() {}
<span class="literal">public</span> A1(<span class="literal">int</span> x) {<span class="literal">this</span>.<span class="ST1">x</span> = x;}
@Override
<span class="literal">public</span> <span class="literal">int</span> <span class="ST2">compareTo</span>(A1 o)
{
<span class="literal">return</span> <span class="literal">this</span>.<span class="ST1">x</span> - o.<span class="ST1">x</span>;
}
@Override
<span class="literal">public</span> String <span class="ST2">toString</span>()
{
<span class="literal">return</span> <span class="string">&quot;</span><span class="string">A1{</span><span class="string">&quot;</span> + <span class="string">&quot;</span><span class="string">x=</span><span class="string">&quot;</span> + <span class="ST1">x</span> + <span class="string">&#39;</span><span class="string">}</span><span class="string">&#39;</span>;
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST3">main</span>(String[] args)
{
System.<span class="ST4">out</span>.println(<span class="string">&quot;</span><span class="string">Sorting in ascending order</span><span class="string">&quot;</span>);
List&lt;A1&gt; list1 = Arrays.<span class="ST5">asList</span>(<span class="literal">new</span> A1(<span class="number">3</span>), <span class="literal">new</span> A1(), <span class="literal">new</span> A1(<span class="number">2</span>));
Collections.<span class="ST5">sort</span>(list1);
System.<span class="ST4">out</span>.println(list1);
System.<span class="ST4">out</span>.println(<span class="string">&quot;</span><span class="string">Sorting in descending order</span><span class="string">&quot;</span>);
Collections.<span class="ST5">sort</span>(list1, Collections.<span class="ST5">reverseOrder</span>());
System.<span class="ST4">out</span>.println(list1);
}
}
</pre></body>
</html>

@ -0,0 +1,90 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>A2.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; font-weight: bold}
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
.string {color: #6a8759}
.number {color: #6897bb}
.ST1 {color: #9876aa}
.ST2 {color: #ffc66d}
.comment {color: #808080}
.whitespace {color: #505050}
.ST3 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
.ST5 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
.ST0 {color: #287bde}
.literal {color: #cc7832}
.ST4 {font-family: monospace; font-weight: bold; font-style: italic}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/JavaFXBallsWithComparator/src/main/java/edu/slcc/asdv/caleb/javafxballswithcomparator/A2.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> edu.slcc.asdv.caleb.javafxballswithcomparator;
<span class="literal">import</span> java.util.Arrays;
<span class="literal">import</span> java.util.Collections;
<span class="literal">import</span> java.util.Comparator;
<span class="literal">import</span> java.util.List;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> A2 {
<span class="literal">int</span> <span class="ST1">x</span>;
<span class="literal">public</span> A2() {
}
<span class="literal">public</span> A2(<span class="literal">int</span> x) {
<span class="literal">this</span>.<span class="ST1">x</span> = x;
}
@Override
<span class="literal">public</span> String <span class="ST2">toString</span>() {
<span class="literal">return</span> <span class="string">&quot;</span><span class="string">A2{</span><span class="string">&quot;</span> + <span class="string">&quot;</span><span class="string">x=</span><span class="string">&quot;</span> + <span class="ST1">x</span> + <span class="string">&#39;</span><span class="string">}</span><span class="string">&#39;</span>;
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST3">main</span>(String[] args) {
List&lt;A2&gt; list1 = Arrays.<span class="ST4">asList</span>(<span class="literal">new</span> A2(<span class="number">4</span>), <span class="literal">new</span> A2(), <span class="literal">new</span> A2(<span class="number">2</span>));
Comparator&lt;A2&gt; c = <span class="literal">new</span> Comparator&lt;A2&gt;() {
@Override
<span class="literal">public</span> <span class="literal">int</span> <span class="ST2">compare</span>(A2 o1, A2 o2) {
<span class="literal">return</span> o1.<span class="ST1">x</span> - o2.<span class="ST1">x</span>;
}
};
Comparator&lt;A2&gt; c2 = <span class="literal">new</span> Comparator&lt;A2&gt;() {
@Override
<span class="literal">public</span> <span class="literal">int</span> <span class="ST2">compare</span>(A2 o1, A2 o2) {
<span class="literal">int</span> returnVal = <span class="number">0</span>;
<span class="literal">if</span>(o1.<span class="ST1">x</span> &gt; o2.<span class="ST1">x</span>) {
returnVal = -<span class="number">1</span>;
} <span class="literal">else</span> {
returnVal = <span class="number">0</span>;
}
<span class="literal">return</span> returnVal;
}
};
System.<span class="ST5">out</span>.println(<span class="string">&quot;</span><span class="string">Sorting in ascending order</span><span class="string">&quot;</span>);
Collections.<span class="ST4">sort</span>(list1, c);
System.<span class="ST5">out</span>.println(list1);
System.<span class="ST5">out</span>.println(<span class="string">&quot;</span><span class="string">Sorting in desending order</span><span class="string">&quot;</span>);
Collections.<span class="ST4">sort</span>(list1,c2);
System.<span class="ST5">out</span>.println(list1);
}
}
</pre></body>
</html>

@ -0,0 +1,93 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>A3.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; font-weight: bold}
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
.string {color: #6a8759}
.number {color: #6897bb}
.ST1 {color: #9876aa}
.ST2 {color: #ffc66d}
.comment {color: #808080}
.whitespace {color: #505050}
.ST3 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
.ST5 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
.ST0 {color: #287bde}
.literal {color: #cc7832}
.ST4 {font-family: monospace; font-weight: bold; font-style: italic}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/JavaFXBallsWithComparator/src/main/java/edu/slcc/asdv/caleb/javafxballswithcomparator/A3.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> edu.slcc.asdv.caleb.javafxballswithcomparator;
<span class="literal">import</span> java.util.Arrays;
<span class="literal">import</span> java.util.Collections;
<span class="literal">import</span> java.util.Comparator;
<span class="literal">import</span> java.util.List;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> A3 {
<span class="literal">int</span> <span class="ST1">x</span>;
<span class="literal">public</span> A3() {
}
<span class="literal">public</span> A3(<span class="literal">int</span> x) {
<span class="literal">this</span>.<span class="ST1">x</span> = x;
}
@Override
<span class="literal">public</span> String <span class="ST2">toString</span>() {
<span class="literal">return</span> <span class="string">&quot;</span><span class="string">A2{</span><span class="string">&quot;</span> + <span class="string">&quot;</span><span class="string">x=</span><span class="string">&quot;</span> + <span class="ST1">x</span> + <span class="string">&#39;</span><span class="string">}</span><span class="string">&#39;</span>;
}
<span class="literal">public</span> <span class="literal">static</span> Comparator&lt;A3&gt; <span class="ST3">comparator</span>() {
Comparator&lt;A3&gt; c = <span class="literal">new</span> Comparator&lt;A3&gt;() {
@Override
<span class="literal">public</span> <span class="literal">int</span> <span class="ST2">compare</span>(A3 o1, A3 o2) {
<span class="literal">return</span> o1.<span class="ST1">x</span> - o2.<span class="ST1">x</span>;
}
};
<span class="literal">return</span> c;
}
<span class="literal">public</span> <span class="literal">static</span> Comparator&lt;A3&gt; <span class="ST3">comparatorReverse</span>() {
Comparator&lt;A3&gt; c = <span class="literal">new</span> Comparator&lt;A3&gt;() {
@Override
<span class="literal">public</span> <span class="literal">int</span> <span class="ST2">compare</span>(A3 o1, A3 o2) {
<span class="literal">return</span> o1.<span class="ST1">x</span> &gt; o2.<span class="ST1">x</span> ? -<span class="number">1</span> : <span class="number">0</span>;
}
};
<span class="literal">return</span> c;
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST3">main</span>(String[] args) {
List&lt;A3&gt; list1 = Arrays.<span class="ST4">asList</span>(<span class="literal">new</span> A3(<span class="number">4</span>), <span class="literal">new</span> A3(), <span class="literal">new</span> A3(<span class="number">2</span>));
System.<span class="ST5">out</span>.println(<span class="string">&quot;</span><span class="string">Sorting in ascending order</span><span class="string">&quot;</span>);
Collections.<span class="ST4">sort</span>(list1, A3.<span class="ST4">comparator</span>());
System.<span class="ST5">out</span>.println(list1);
System.<span class="ST5">out</span>.println(<span class="string">&quot;</span><span class="string">Sorting in desending order</span><span class="string">&quot;</span>);
Collections.<span class="ST4">sort</span>(list1, A3.<span class="ST4">comparatorReverse</span>());
System.<span class="ST5">out</span>.println(list1);
}
}
</pre></body>
</html>

@ -0,0 +1,110 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>A4.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; font-weight: bold}
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
.number {color: #6897bb}
.string {color: #6a8759}
.ST1 {color: #9876aa}
.ST3 {color: #ffc66d}
.comment {color: #808080}
.whitespace {color: #505050}
.ST2 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
.ST4 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
.ST0 {color: #287bde}
.literal {color: #cc7832}
.ST5 {font-family: monospace; font-weight: bold; font-style: italic}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/JavaFXBallsWithComparator/src/main/java/edu/slcc/asdv/caleb/javafxballswithcomparator/A4.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> edu.slcc.asdv.caleb.javafxballswithcomparator;
<span class="literal">import</span> java.util.Arrays;
<span class="literal">import</span> java.util.Collections;
<span class="literal">import</span> java.util.Comparator;
<span class="literal">import</span> java.util.List;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> A4&lt;E <span class="literal">extends</span> Comparable&lt;E&gt;&gt; {
E <span class="ST1">x</span>;
<span class="literal">public</span> A4() {}
<span class="literal">public</span> A4(E x) {<span class="literal">this</span>.<span class="ST1">x</span> = x;}
<span class="literal">public</span> <span class="literal">static</span> Comparator&lt;A4&gt; <span class="ST2">comparator</span>() {
Comparator&lt;A4&gt; c = <span class="literal">new</span> Comparator&lt;A4&gt;() {
@Override
<span class="literal">public</span> <span class="literal">int</span> <span class="ST3">compare</span>(A4 o1, A4 o2) {
<span class="literal">return</span> o1.<span class="ST1">x</span>.compareTo(o2.<span class="ST1">x</span>);
}
};
<span class="literal">return</span> c;
}
<span class="literal">public</span> <span class="literal">static</span> Comparator&lt;A4&gt; <span class="ST2">comparatorReverse</span>() {
Comparator&lt;A4&gt; c = <span class="literal">new</span> Comparator&lt;A4&gt;() {
@Override
<span class="literal">public</span> <span class="literal">int</span> <span class="ST3">compare</span>(A4 o1, A4 o2) {
<span class="literal">switch</span> (o1.<span class="ST1">x</span>.compareTo(o2.<span class="ST1">x</span>)) {
<span class="literal">case</span> -<span class="number">1</span>:
<span class="literal">return</span> <span class="number">1</span>;
<span class="literal">case</span> <span class="number">0</span>:
<span class="literal">return</span> <span class="number">0</span>;
<span class="literal">case</span> <span class="number">1</span>:
<span class="literal">return</span> -<span class="number">1</span>;
}
<span class="literal">return</span> -<span class="number">112315234</span>;
}
};
<span class="literal">return</span> c;
}
@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">A4{</span><span class="string">&quot;</span> + <span class="string">&quot;</span><span class="string">x=</span><span class="string">&quot;</span> + <span class="ST1">x</span> + <span class="string">&#39;</span><span class="string">}</span><span class="string">&#39;</span>;
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST2">main</span>(String[] args) {
System.<span class="ST4">out</span>.println(<span class="string">&quot;</span><span class="string">Sorting in ascending order</span><span class="string">&quot;</span>);
List&lt;A4&gt; list1 = Arrays.<span class="ST5">asList</span>(
<span class="literal">new</span> A4(<span class="literal">new</span> Integer(<span class="number">4</span>)),
<span class="literal">new</span> A4(<span class="literal">new</span> Integer(<span class="number">1</span>)),
<span class="literal">new</span> A4(<span class="literal">new</span> Integer(<span class="number">2</span>))
);
Collections.<span class="ST5">sort</span>(list1, A4.<span class="ST5">comparator</span>());
List&lt;A4&gt; list2 = Arrays.<span class="ST5">asList</span>(
<span class="literal">new</span> A4(<span class="literal">new</span> String(<span class="string">&quot;</span><span class="string">once</span><span class="string">&quot;</span>)),
<span class="literal">new</span> A4(<span class="literal">new</span> String(<span class="string">&quot;</span><span class="string">upon</span><span class="string">&quot;</span>)),
<span class="literal">new</span> A4(<span class="literal">new</span> String(<span class="string">&quot;</span><span class="string">a</span><span class="string">&quot;</span>)),
<span class="literal">new</span> A4(<span class="literal">new</span> String(<span class="string">&quot;</span><span class="string">time</span><span class="string">&quot;</span>)),
<span class="literal">new</span> A4(<span class="literal">new</span> String(<span class="string">&quot;</span><span class="string">in</span><span class="string">&quot;</span>)),
<span class="literal">new</span> A4(<span class="literal">new</span> String(<span class="string">&quot;</span><span class="string">America</span><span class="string">&quot;</span>))
);
Collections.<span class="ST5">sort</span>(list2, A4.<span class="ST5">comparator</span>());
System.<span class="ST4">out</span>.println(list1);
System.<span class="ST4">out</span>.println(list2);
System.<span class="ST4">out</span>.println(<span class="string">&quot;</span><span class="string">Now, in descending order:</span><span class="string">&quot;</span>);
Collections.<span class="ST5">sort</span>(list2, A4.<span class="ST5">comparatorReverse</span>());
System.<span class="ST4">out</span>.println(list2);
}
}
</pre></body>
</html>

@ -0,0 +1,75 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Circle.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; font-weight: bold}
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
.number {color: #6897bb}
.string {color: #6a8759}
.comment {color: #808080}
.whitespace {color: #505050}
.literal {color: #cc7832}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/JavaFXBallsWithComparator/src/main/java/edu/slcc/asdv/caleb/javafxballswithcomparator/Circle.java</td></tr></table>
<pre>
<span class="comment">/*</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template</span>
<span class="comment"> */</span>
<span class="literal">package</span> edu.slcc.asdv.caleb.javafxballswithcomparator;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> Circle <span class="literal">extends</span> GeometricObject {
<span class="literal">private</span> <span class="literal">double</span> radius;
<span class="literal">public</span> Circle() {
}
<span class="literal">public</span> Circle(<span class="literal">double</span> radius) {
<span class="literal">this</span>.radius = radius;
}
<span class="comment">/**</span> <span class="comment">Return</span> <span class="comment">radius</span> <span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">double</span> getRadius() {
<span class="literal">return</span> radius;
}
<span class="comment">/**</span> <span class="comment">Set</span> <span class="comment">a</span> <span class="comment">new</span> <span class="comment">radius</span> <span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">void</span> setRadius(<span class="literal">double</span> radius) {
<span class="literal">this</span>.radius = radius;
}
@Override <span class="comment">/**</span> <span class="comment">Return</span> <span class="comment">area</span> <span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">double</span> getArea() {
<span class="literal">return</span> radius * radius * Math.PI;
}
<span class="comment">/**</span> <span class="comment">Return</span> <span class="comment">diameter</span> <span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">double</span> getDiameter() {
<span class="literal">return</span> <span class="number">2</span> * radius;
}
@Override <span class="comment">/**</span> <span class="comment">Return</span> <span class="comment">perimeter</span> <span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">double</span> getPerimeter() {
<span class="literal">return</span> <span class="number">2</span> * radius * Math.PI;
}
<span class="comment">/* Print the circle info */</span>
<span class="literal">public</span> <span class="literal">void</span> printCircle() {
System.out.println(<span class="string">&quot;</span><span class="string">The circle is created </span><span class="string">&quot;</span> + getDateCreated() +
<span class="string">&quot;</span><span class="string"> and the radius is </span><span class="string">&quot;</span> + radius);
}
}
</pre></body>
</html>

@ -0,0 +1,89 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>GeometricObject.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; font-weight: bold}
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
.string {color: #6a8759}
.comment {color: #808080}
.whitespace {color: #505050}
.literal {color: #cc7832}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/JavaFXBallsWithComparator/src/main/java/edu/slcc/asdv/caleb/javafxballswithcomparator/GeometricObject.java</td></tr></table>
<pre>
<span class="comment">/*</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template</span>
<span class="comment"> */</span>
<span class="literal">package</span> edu.slcc.asdv.caleb.javafxballswithcomparator;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="comment">@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> GeometricObject {
<span class="literal">private</span> String color = <span class="string">&quot;</span><span class="string">white</span><span class="string">&quot;</span>;
<span class="literal">private</span> <span class="literal">boolean</span> filled;
<span class="literal">private</span> java.util.Date dateCreated;
<span class="comment">/**</span> <span class="comment">Construct</span> <span class="comment">a</span> <span class="comment">default</span> <span class="comment">geometric</span> <span class="comment">object</span> <span class="comment">*/</span>
<span class="literal">protected</span> GeometricObject() {
dateCreated = <span class="literal">new</span> java.util.Date();
}
<span class="comment">/**</span> <span class="comment">Construct</span> <span class="comment">a</span> <span class="comment">geometric</span> <span class="comment">object</span> <span class="comment">with</span> <span class="comment">color</span> <span class="comment">and</span> <span class="comment">filled</span> <span class="comment">value</span> <span class="comment">*/</span>
<span class="literal">protected</span> GeometricObject(String color, <span class="literal">boolean</span> filled) {
dateCreated = <span class="literal">new</span> java.util.Date();
<span class="literal">this</span>.color = color;
<span class="literal">this</span>.filled = filled;
}
<span class="comment">/**</span> <span class="comment">Return</span> <span class="comment">color</span> <span class="comment">*/</span>
<span class="literal">public</span> String getColor() {
<span class="literal">return</span> color;
}
<span class="comment">/**</span> <span class="comment">Set</span> <span class="comment">a</span> <span class="comment">new</span> <span class="comment">color</span> <span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">void</span> setColor(String color) {
<span class="literal">this</span>.color = color;
}
<span class="comment">/**</span> <span class="comment">Return</span> <span class="comment">filled</span><span class="comment">.</span> <span class="comment">Since</span> <span class="comment">filled</span> <span class="comment">is</span> <span class="comment">boolean</span><span class="comment">,</span>
<span class="comment"> * </span><span class="comment">the</span> <span class="comment">get</span> <span class="comment">method</span> <span class="comment">is</span> <span class="comment">named</span> <span class="comment">isFilled</span> <span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">boolean</span> isFilled() {
<span class="literal">return</span> filled;
}
<span class="comment">/**</span> <span class="comment">Set</span> <span class="comment">a</span> <span class="comment">new</span> <span class="comment">filled</span> <span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">void</span> setFilled(<span class="literal">boolean</span> filled) {
<span class="literal">this</span>.filled = filled;
}
<span class="comment">/**</span> <span class="comment">Get</span> <span class="comment">dateCreated</span> <span class="comment">*/</span>
<span class="literal">public</span> java.util.Date getDateCreated() {
<span class="literal">return</span> dateCreated;
}
@Override
<span class="literal">public</span> String toString() {
<span class="literal">return</span> <span class="string">&quot;</span><span class="string">created on </span><span class="string">&quot;</span> + dateCreated + <span class="string">&quot;</span><span class="literal">\n</span><span class="string">color: </span><span class="string">&quot;</span> + color +
<span class="string">&quot;</span><span class="string"> and filled: </span><span class="string">&quot;</span> + filled;
}
<span class="comment">/**</span> <span class="comment">Abstract</span> <span class="comment">method</span> <span class="comment">getArea</span> <span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">abstract</span> <span class="literal">double</span> getArea();
<span class="comment">/**</span> <span class="comment">Abstract</span> <span class="comment">method</span> <span class="comment">getPerimeter</span> <span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">abstract</span> <span class="literal">double</span> getPerimeter();
}
</pre></body>
</html>

@ -0,0 +1,42 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>GeometricObjectComparator.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; font-weight: bold}
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
.number {color: #6897bb}
.comment {color: #808080}
.whitespace {color: #505050}
.literal {color: #cc7832}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/JavaFXBallsWithComparator/src/main/java/edu/slcc/asdv/caleb/javafxballswithcomparator/GeometricObjectComparator.java</td></tr></table>
<pre>
<span class="comment">/*</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template</span>
<span class="comment"> */</span>
<span class="literal">package</span> edu.slcc.asdv.caleb.javafxballswithcomparator;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
<span class="comment">*/</span>
<span class="literal">import</span> java.util.Comparator;
<span class="literal">public</span> <span class="literal">class</span> GeometricObjectComparator
<span class="literal">implements</span> Comparator&lt;GeometricObject&gt;, java.io.Serializable {
<span class="literal">public</span> <span class="literal">int</span> compare(GeometricObject o1, GeometricObject o2) {
<span class="literal">return</span> o1.getArea() &gt; o2.getArea() ?
<span class="number">1</span> : o1.getArea() == o2.getArea() ? <span class="number">0</span> : -<span class="number">1</span>;
}
}
</pre></body>
</html>

@ -0,0 +1,209 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>MultipleBallsWithComparator.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; font-weight: bold}
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
.string {color: #6a8759}
.number {color: #6897bb}
.whitespace {color: #505050}
.comment {color: #808080}
.literal {color: #cc7832}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/JavaFXBallsWithComparator/src/main/java/edu/slcc/asdv/caleb/javafxballswithcomparator/MultipleBallsWithComparator.java</td></tr></table>
<pre>
<span class="literal">package</span> edu.slcc.asdv.caleb.javafxballswithcomparator;
<span class="literal">import</span> javafx.animation.KeyFrame;
<span class="literal">import</span> javafx.animation.Timeline;
<span class="literal">import</span> javafx.application.Application;
<span class="literal">import</span> javafx.beans.property.DoubleProperty;
<span class="literal">import</span> javafx.geometry.Pos;
<span class="literal">import</span> javafx.scene.Node;
<span class="literal">import</span> javafx.stage.Stage;
<span class="literal">import</span> javafx.scene.Scene;
<span class="literal">import</span> javafx.scene.control.Button;
<span class="literal">import</span> javafx.scene.control.ScrollBar;
<span class="literal">import</span> javafx.scene.layout.BorderPane;
<span class="literal">import</span> javafx.scene.layout.HBox;
<span class="literal">import</span> javafx.scene.layout.Pane;
<span class="literal">import</span> javafx.scene.paint.Color;
<span class="literal">import</span> javafx.scene.shape.Circle;
<span class="literal">import</span> javafx.util.Duration;
<span class="literal">public</span> <span class="literal">class</span> MultipleBallsWithComparator <span class="literal">extends</span> Application
{
@Override <span class="comment">// Override the start method in the Application class</span>
<span class="literal">public</span> <span class="literal">void</span> start(Stage primaryStage)
{
MultipleBallPane ballPane = <span class="literal">new</span> MultipleBallPane();
Button btAdd = <span class="literal">new</span> Button(<span class="string">&quot;</span><span class="string">+</span><span class="string">&quot;</span>);
Button btSubtract = <span class="literal">new</span> Button(<span class="string">&quot;</span><span class="string">-</span><span class="string">&quot;</span>);
HBox hBox = <span class="literal">new</span> HBox(<span class="number">10</span>);
hBox.getChildren().addAll(btAdd, btSubtract);
hBox.setAlignment(Pos.CENTER);
<span class="comment">// Add or remove a ball</span>
btAdd.setOnAction(e -&gt; ballPane.add());
btSubtract.setOnAction(e -&gt; ballPane.subtract());
<span class="comment">// Pause and resume animation</span>
ballPane.setOnMousePressed(e -&gt; ballPane.pause());
ballPane.setOnMouseReleased(e -&gt; ballPane.play());
<span class="comment">// Use a scroll bar to control animation speed</span>
ScrollBar sbSpeed = <span class="literal">new</span> ScrollBar();
sbSpeed.setMax(<span class="number">20</span>);
sbSpeed.setValue(<span class="number">10</span>);
ballPane.rateProperty().bind(sbSpeed.valueProperty());
BorderPane pane = <span class="literal">new</span> BorderPane();
pane.setCenter(ballPane);
pane.setTop(sbSpeed);
pane.setBottom(hBox);
<span class="comment">// Create a scene and place the pane in the stage</span>
Scene scene = <span class="literal">new</span> Scene(pane, <span class="number">250</span>, <span class="number">150</span>);
primaryStage.setTitle(<span class="string">&quot;</span><span class="string">Multiple Bouncing Balls</span><span class="string">&quot;</span>); <span class="comment">// Set the stage title</span>
primaryStage.setScene(scene); <span class="comment">// Place the scene in the stage</span>
primaryStage.show(); <span class="comment">// Display the stage</span>
}
<span class="literal">private</span> <span class="literal">class</span> MultipleBallPane <span class="literal">extends</span> Pane
{
<span class="literal">private</span> Timeline animation;
<span class="literal">public</span> MultipleBallPane()
{
<span class="comment">// Create an animation for moving the ball</span>
animation = <span class="literal">new</span> Timeline(
<span class="literal">new</span> KeyFrame(Duration.millis(<span class="number">50</span>), e -&gt; moveBall()));
animation.setCycleCount(Timeline.INDEFINITE);
animation.play(); <span class="comment">// Start animation</span>
}
<span class="literal">public</span> <span class="literal">void</span> add()
{
Color color = <span class="literal">new</span> Color(Math.random(),
Math.random(), Math.random(), <span class="number">0.5</span>);
getChildren().add(<span class="literal">new</span> Ball(<span class="number">30</span>, <span class="number">30</span>, Math.random() * <span class="number">16</span> + <span class="number">5</span>, color));
}
<span class="literal">public</span> <span class="literal">void</span> subtract()
{
<span class="literal">if</span> (getChildren().size() &gt; <span class="number">0</span>)
{
<span class="comment">//&gt; Locate the ball with the largest radius</span>
Ball ball = (Ball) (getChildren().get(<span class="number">0</span>));
<span class="literal">for</span> (Node node : getChildren())
{
<span class="literal">if</span> (((Ball) node).getRadius() &gt; ball.getRadius())
{
ball = (Ball) node;
}
}
getChildren().remove(ball);
}
}
<span class="literal">public</span> <span class="literal">void</span> play()
{
animation.play();
}
<span class="literal">public</span> <span class="literal">void</span> pause()
{
animation.pause();
}
<span class="literal">public</span> <span class="literal">void</span> increaseSpeed()
{
animation.setRate(animation.getRate() + <span class="number">0.1</span>);
}
<span class="literal">public</span> <span class="literal">void</span> decreaseSpeed()
{
animation.setRate(
animation.getRate() &gt; <span class="number">0</span> ? animation.getRate() - <span class="number">0.1</span> : <span class="number">0</span>);
}
<span class="literal">public</span> DoubleProperty rateProperty()
{
<span class="literal">return</span> animation.rateProperty();
}
<span class="literal">protected</span> <span class="literal">void</span> moveBall()
{
<span class="literal">for</span> (Node node : <span class="literal">this</span>.getChildren())
{
Ball ball = (Ball) node;
<span class="comment">// Check boundaries</span>
<span class="literal">if</span> (ball.getCenterX() &lt; ball.getRadius()
|| ball.getCenterX() &gt; getWidth() - ball.getRadius())
{
ball.dx *= -<span class="number">1</span>; <span class="comment">// Change ball move direction</span>
}
<span class="literal">if</span> (ball.getCenterY() &lt; ball.getRadius()
|| ball.getCenterY() &gt; getHeight() - ball.getRadius())
{
ball.dy *= -<span class="number">1</span>; <span class="comment">// Change ball move direction</span>
}
<span class="comment">// Adjust ball position</span>
ball.setCenterX(ball.dx + ball.getCenterX());
ball.setCenterY(ball.dy + ball.getCenterY());
}
}
}
<span class="literal">class</span> Ball <span class="literal">extends</span> Circle <span class="literal">implements</span> Comparable&lt;Ball&gt;
{
<span class="literal">private</span> <span class="literal">double</span> dx = <span class="number">1</span>, dy = <span class="number">1</span>;
Ball(<span class="literal">double</span> x, <span class="literal">double</span> y, <span class="literal">double</span> radius, Color color)
{
<span class="literal">super</span>(x, y, radius);
setFill(color); <span class="comment">// Set ball color</span>
}
<span class="literal">public</span> <span class="literal">int</span> compareTo(Ball b)
{
<span class="literal">if</span> (<span class="literal">this</span>.getRadius() - b.getRadius() &lt; <span class="number">0</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>.getRadius() - b.getRadius() == <span class="number">0</span>)
{
<span class="literal">return</span> <span class="number">0</span>;
}
<span class="literal">else</span>
{
<span class="literal">return</span> <span class="number">1</span>;
}
}
}
<span class="comment">/**</span>
<span class="comment"> * </span><span class="comment">The</span> <span class="comment">main</span> <span class="comment">method</span> <span class="comment">is</span> <span class="comment">only</span> <span class="comment">needed</span> <span class="comment">for</span> <span class="comment">the</span> <span class="comment">IDE</span> <span class="comment">with</span> <span class="comment">limited</span> <span class="comment">JavaFX</span> <span class="comment">support</span><span class="comment">.</span>
<span class="comment"> * </span><span class="comment">Not</span> <span class="comment">needed</span> <span class="comment">for</span> <span class="comment">running</span> <span class="comment">from</span> <span class="comment">the</span> <span class="comment">command</span> <span class="comment">line</span><span class="comment">.</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args)
{
launch(args);
}
}
</pre></body>
</html>

@ -0,0 +1,76 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Rectangle.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; font-weight: bold}
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
.number {color: #6897bb}
.comment {color: #808080}
.whitespace {color: #505050}
.literal {color: #cc7832}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/JavaFXBallsWithComparator/src/main/java/edu/slcc/asdv/caleb/javafxballswithcomparator/Rectangle.java</td></tr></table>
<pre>
<span class="comment">/*</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template</span>
<span class="comment"> */</span>
<span class="literal">package</span> edu.slcc.asdv.caleb.javafxballswithcomparator;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> Rectangle <span class="literal">extends</span> GeometricObject {
<span class="literal">private</span> <span class="literal">double</span> width;
<span class="literal">private</span> <span class="literal">double</span> height;
<span class="literal">public</span> Rectangle() {
}
<span class="literal">public</span> Rectangle(<span class="literal">double</span> width, <span class="literal">double</span> height) {
<span class="literal">this</span>.width = width;
<span class="literal">this</span>.height = height;
}
<span class="comment">/**</span> <span class="comment">Return</span> <span class="comment">width</span> <span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">double</span> getWidth() {
<span class="literal">return</span> width;
}
<span class="comment">/**</span> <span class="comment">Set</span> <span class="comment">a</span> <span class="comment">new</span> <span class="comment">width</span> <span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">void</span> setWidth(<span class="literal">double</span> width) {
<span class="literal">this</span>.width = width;
}
<span class="comment">/**</span> <span class="comment">Return</span> <span class="comment">height</span> <span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">double</span> getHeight() {
<span class="literal">return</span> height;
}
<span class="comment">/**</span> <span class="comment">Set</span> <span class="comment">a</span> <span class="comment">new</span> <span class="comment">height</span> <span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">void</span> setHeight(<span class="literal">double</span> height) {
<span class="literal">this</span>.height = height;
}
@Override <span class="comment">/**</span> <span class="comment">Return</span> <span class="comment">area</span> <span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">double</span> getArea() {
<span class="literal">return</span> width * height;
}
@Override <span class="comment">/**</span> <span class="comment">Return</span> <span class="comment">perimeter</span> <span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">double</span> getPerimeter() {
<span class="literal">return</span> <span class="number">2</span> * (width + height);
}
}
</pre></body>
</html>

@ -0,0 +1,68 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>TestArrayAndLinkedList.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; font-weight: bold}
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
.number {color: #6897bb}
.string {color: #6a8759}
.whitespace {color: #505050}
.literal {color: #cc7832}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/JavaFXBallsWithComparator/src/main/java/edu/slcc/asdv/caleb/javafxballswithcomparator/TestArrayAndLinkedList.java</td></tr></table>
<pre>
<span class="literal">package</span> edu.slcc.asdv.caleb.javafxballswithcomparator;
<span class="literal">import</span> java.util.ArrayList;
<span class="literal">import</span> java.util.LinkedList;
<span class="literal">import</span> java.util.List;
<span class="literal">import</span> java.util.ListIterator;
<span class="literal">public</span> <span class="literal">class</span> TestArrayAndLinkedList
{
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args)
{
List&lt;Integer&gt; arrayList = <span class="literal">new</span> ArrayList&lt;&gt;();
arrayList.add(<span class="number">1</span>);
arrayList.add(<span class="number">2</span>);
arrayList.add(<span class="number">3</span>);
arrayList.add(<span class="number">1</span>);
arrayList.add(<span class="number">4</span>);
arrayList.add(<span class="number">0</span>, <span class="number">10</span>);
arrayList.add(<span class="number">3</span>, <span class="number">30</span>);
System.out.println(<span class="string">&quot;</span><span class="string">A list of integers in the array list:</span><span class="string">&quot;</span>);
System.out.println(arrayList);
LinkedList&lt;Object&gt; linkedList = <span class="literal">new</span> LinkedList&lt;&gt;(arrayList);
linkedList.add(<span class="number">1</span>, <span class="string">&quot;</span><span class="string">red</span><span class="string">&quot;</span>);
linkedList.removeLast();
linkedList.addFirst(<span class="string">&quot;</span><span class="string">green</span><span class="string">&quot;</span>);
System.out.println(<span class="string">&quot;</span><span class="string">Display the linked list backward:</span><span class="string">&quot;</span>);
ListIterator&lt;Object&gt; listIterator = linkedList.listIterator();
<span class="literal">while</span> (listIterator.hasNext())
{
System.out.print(listIterator.next() + <span class="string">&quot;</span> <span class="string">&quot;</span>);
}
System.out.println();
System.out.println(<span class="string">&quot;</span><span class="string">Display the linked list backward:</span><span class="string">&quot;</span>);
listIterator = linkedList.listIterator(linkedList.size());
<span class="literal">while</span> (listIterator.hasPrevious())
{
System.out.print(listIterator.previous() + <span class="string">&quot;</span> <span class="string">&quot;</span>);
}
}
}
</pre></body>
</html>

@ -0,0 +1,53 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>TestComparator.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; font-weight: bold}
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
.number {color: #6897bb}
.string {color: #6a8759}
.comment {color: #808080}
.whitespace {color: #505050}
.literal {color: #cc7832}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/JavaFXBallsWithComparator/src/main/java/edu/slcc/asdv/caleb/javafxballswithcomparator/TestComparator.java</td></tr></table>
<pre>
<span class="comment">/*</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template</span>
<span class="comment"> */</span>
<span class="literal">package</span> edu.slcc.asdv.caleb.javafxballswithcomparator;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
<span class="comment">*/</span>
<span class="literal">import</span> java.util.Comparator;
<span class="literal">public</span> <span class="literal">class</span> TestComparator {
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args) {
GeometricObject g1 = <span class="literal">new</span> Rectangle(<span class="number">5</span>, <span class="number">5</span>);
GeometricObject g2 = <span class="literal">new</span> Circle(<span class="number">5</span>);
GeometricObject g =
max(g1, g2, <span class="literal">new</span> GeometricObjectComparator());
System.out.println(<span class="string">&quot;</span><span class="string">The area of the larger object is </span><span class="string">&quot;</span> +
g.getArea());
}
<span class="literal">public</span> <span class="literal">static</span> GeometricObject max(GeometricObject g1,
GeometricObject g2, Comparator&lt;GeometricObject&gt; c) {
<span class="literal">return</span> c.compare(g1, g2) &gt; <span class="number">0</span> ? g1 : g2;
}
}
</pre></body>
</html>

@ -0,0 +1,68 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>TestPriorityQueue.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; font-weight: bold}
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
.string {color: #6a8759}
.number {color: #6897bb}
.comment {color: #808080}
.whitespace {color: #505050}
.ST1 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
.ST0 {color: #287bde}
.literal {color: #cc7832}
.ST3 {font-family: monospace; font-weight: bold; font-style: italic}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/JavaFXBallsWithComparator/src/main/java/edu/slcc/asdv/caleb/javafxballswithcomparator/TestPriorityQueue.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> edu.slcc.asdv.caleb.javafxballswithcomparator;
<span class="literal">import</span> java.util.Collections;
<span class="literal">import</span> java.util.Comparator;
<span class="literal">import</span> java.util.PriorityQueue;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> TestPriorityQueue {
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
PriorityQueue&lt;String&gt; queue1 = <span class="literal">new</span> PriorityQueue&lt;&gt;();
queue1.offer(<span class="string">&quot;</span><span class="string">Oklahoma</span><span class="string">&quot;</span>);
queue1.offer(<span class="string">&quot;</span><span class="string">Indiana</span><span class="string">&quot;</span>);
queue1.offer(<span class="string">&quot;</span><span class="string">Georgia</span><span class="string">&quot;</span>);
queue1.offer(<span class="string">&quot;</span><span class="string">Texas</span><span class="string">&quot;</span>);
System.<span class="ST2">out</span>.println(<span class="string">&quot;</span><span class="string">Priority queue using Comparable:</span><span class="string">&quot;</span>);
<span class="literal">while</span> (queue1.size() &gt; <span class="number">0</span>) {
System.<span class="ST2">out</span>.print(queue1.remove() + <span class="string">&quot;</span> <span class="string">&quot;</span>);
}
Comparator&lt;String&gt; c = Collections.<span class="ST3">reverseOrder</span>();
PriorityQueue&lt;String&gt; queue2 = <span class="literal">new</span> PriorityQueue&lt;&gt;(<span class="number">4</span>, c);
queue2.offer(<span class="string">&quot;</span><span class="string">Oklahoma</span><span class="string">&quot;</span>);
queue2.offer(<span class="string">&quot;</span><span class="string">Indiana</span><span class="string">&quot;</span>);
queue2.offer(<span class="string">&quot;</span><span class="string">Georgia</span><span class="string">&quot;</span>);
queue2.offer(<span class="string">&quot;</span><span class="string">Texas</span><span class="string">&quot;</span>);
System.<span class="ST2">out</span>.println(<span class="string">&quot;</span><span class="literal">\n</span><span class="literal">\n</span><span class="string">Priority queue is using Comparator: </span><span class="string">&quot;</span>);
<span class="literal">while</span> (queue2.size() &gt; <span class="number">0</span>) {
System.<span class="ST2">out</span>.print(queue2.remove() + <span class="string">&quot;</span> <span class="string">&quot;</span>);
}
}
}
</pre></body>
</html>

@ -0,0 +1,128 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>TestTheCollections.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; font-weight: bold}
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
.string {color: #6a8759}
.number {color: #6897bb}
.comment {color: #808080}
.whitespace {color: #505050}
.ST1 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
.ST0 {color: #287bde}
.literal {color: #cc7832}
.ST3 {font-family: monospace; font-weight: bold; font-style: italic}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/JavaFXBallsWithComparator/src/main/java/edu/slcc/asdv/caleb/javafxballswithcomparator/TestTheCollections.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> edu.slcc.asdv.caleb.javafxballswithcomparator;
<span class="literal">import</span> java.util.ArrayList;
<span class="literal">import</span> java.util.Arrays;
<span class="literal">import</span> java.util.Collection;
<span class="literal">import</span> java.util.Collections;
<span class="literal">import</span> java.util.List;
<span class="literal">import</span> java.util.Random;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> TestTheCollections {
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
System.<span class="ST2">out</span>.println(<span class="string">&quot;</span><span class="string">Sorting in ascending order</span><span class="string">&quot;</span>);
List&lt;String&gt; list1 = Arrays.<span class="ST3">asList</span>(<span class="string">&quot;</span><span class="string">red</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">green</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">blue</span><span class="string">&quot;</span>);
Collections.<span class="ST3">sort</span>(list1);
System.<span class="ST2">out</span>.println(list1);
System.<span class="ST2">out</span>.println(<span class="string">&quot;</span><span class="string">Sorting in descending order</span><span class="string">&quot;</span>);
List&lt;String&gt; list2 = Arrays.<span class="ST3">asList</span>(<span class="string">&quot;</span><span class="string">yellow</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">red</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">green</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">blue</span><span class="string">&quot;</span>);
Collections.<span class="ST3">sort</span>(list2);
System.<span class="ST2">out</span>.println(list2);
System.<span class="ST2">out</span>.println(<span class="string">&quot;</span><span class="literal">\n</span><span class="string">Binary Search</span><span class="string">&quot;</span>);
List&lt;Integer&gt; list3
= Arrays.<span class="ST3">asList</span>(<span class="number">2</span>, <span class="number">4</span>, <span class="number">7</span>, <span class="number">1</span><span class="number">0</span>, <span class="number">1</span><span class="number">1</span>, <span class="number">4</span><span class="number">5</span>, <span class="number">5</span><span class="number">0</span>, <span class="number">5</span><span class="number">9</span>, <span class="number">6</span><span class="number">0</span>, <span class="number">6</span><span class="number">6</span>);
System.<span class="ST2">out</span>.println(list3 + <span class="string">&quot;</span><span class="string"> 7 is at index: </span><span class="string">&quot;</span> + Collections.<span class="ST3">binarySearch</span>(list3, <span class="number">7</span>));
System.<span class="ST2">out</span>.println(list3 + <span class="string">&quot;</span><span class="string"> 9 is at index: </span><span class="string">&quot;</span> + Collections.<span class="ST3">binarySearch</span>(list3, <span class="number">9</span>));
System.<span class="ST2">out</span>.println(list3 + <span class="string">&quot;</span><span class="string"> 100 is at index: </span><span class="string">&quot;</span> + Collections.<span class="ST3">binarySearch</span>(list3, <span class="number">1</span><span class="number">00</span>));
List&lt;String&gt; list4 = <span class="literal">new</span> ArrayList&lt;&gt;();
list4.addAll(list1);
System.<span class="ST2">out</span>.println(list4 + <span class="string">&quot;</span><span class="string"> red is at index: </span><span class="string">&quot;</span> + Collections.<span class="ST3">binarySearch</span>(list4, <span class="string">&quot;</span><span class="string">red</span><span class="string">&quot;</span>));
System.<span class="ST2">out</span>.println(list4 + <span class="string">&quot;</span><span class="string"> amber is at index: </span><span class="string">&quot;</span> + Collections.<span class="ST3">binarySearch</span>(list4, <span class="string">&quot;</span><span class="string">amber</span><span class="string">&quot;</span>));
System.<span class="ST2">out</span>.println(list4 + <span class="string">&quot;</span><span class="string"> brown is at index: </span><span class="string">&quot;</span> + Collections.<span class="ST3">binarySearch</span>(list4, <span class="string">&quot;</span><span class="string">brown</span><span class="string">&quot;</span>));
System.<span class="ST2">out</span>.println(<span class="string">&quot;</span><span class="literal">\n</span><span class="string">Reverse the list</span><span class="string">&quot;</span>);
List&lt;String&gt; list5 = <span class="literal">new</span> ArrayList&lt;&gt;();
list5.addAll(list2);
System.<span class="ST2">out</span>.println(<span class="string">&quot;</span><span class="string">Original list: </span><span class="string">&quot;</span> + list5);
Collections.<span class="ST3">reverse</span>(list5);
System.<span class="ST2">out</span>.println(<span class="string">&quot;</span><span class="string">Reversed list: </span><span class="string">&quot;</span> + list5);
System.<span class="ST2">out</span>.println(<span class="string">&quot;</span><span class="literal">\n</span><span class="string">Shuffle lists</span><span class="string">&quot;</span>);
List&lt;String&gt; list6 = <span class="literal">new</span> ArrayList&lt;&gt;();
List&lt;String&gt; list7 = <span class="literal">new</span> ArrayList&lt;&gt;();
list6.addAll(list2);
list7.addAll(list2);
System.<span class="ST2">out</span>.println(<span class="string">&quot;</span><span class="string">Original list: </span><span class="string">&quot;</span> + list6);
Collections.<span class="ST3">shuffle</span>(list6, <span class="literal">new</span> Random(<span class="number">2</span><span class="number">0</span>));
System.<span class="ST2">out</span>.println(<span class="string">&quot;</span><span class="string">Shuffled list: </span><span class="string">&quot;</span> + list6);
System.<span class="ST2">out</span>.println(<span class="string">&quot;</span><span class="string">Original list: </span><span class="string">&quot;</span> + list7);
Collections.<span class="ST3">shuffle</span>(list7, <span class="literal">new</span> Random(<span class="number">2</span><span class="number">0</span>));
System.<span class="ST2">out</span>.println(<span class="string">&quot;</span><span class="string">Shuffled list: </span><span class="string">&quot;</span> + list7);
List&lt;String&gt; list8 = <span class="literal">new</span> ArrayList&lt;&gt;();
list8.addAll(list2);
List&lt;String&gt; list9 = Arrays.<span class="ST3">asList</span>(<span class="string">&quot;</span><span class="string">white</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">black</span><span class="string">&quot;</span>);
System.<span class="ST2">out</span>.println(<span class="string">&quot;</span><span class="literal">\n</span><span class="string">Copy into </span><span class="string">&quot;</span> + list8 + <span class="string">&quot;</span><span class="string"> the list </span><span class="string">&quot;</span> + list9);
Collections.<span class="ST3">copy</span>(list8, list9);
System.<span class="ST2">out</span>.println(list8);
System.<span class="ST2">out</span>.println(<span class="string">&quot;</span><span class="string">The output for list 8 is [white, black, green, blue].</span><span class="literal">\n</span><span class="string">&quot;</span>
+ <span class="string">&quot;</span><span class="string">The copy method performs a </span><span class="literal">\n</span><span class="string">&quot;</span>
+ <span class="string">&quot;</span><span class="string">shallow copy: only the references of the elements fromt he source list are copied.</span><span class="string">&quot;</span>
);
List&lt;String&gt; list10 = <span class="literal">new</span> ArrayList&lt;&gt;();
list10.addAll(list1);
System.<span class="ST2">out</span>.println(<span class="string">&quot;</span><span class="literal">\n</span><span class="string">Fill the list </span><span class="string">&quot;</span> + list10 + <span class="string">&quot;</span><span class="string"> with </span><span class="literal">\&#39;</span><span class="string">black</span><span class="literal">\&#39;</span><span class="string">.</span><span class="string">&quot;</span>);
Collections.<span class="ST3">fill</span>(list10, <span class="string">&quot;</span><span class="string">black</span><span class="string">&quot;</span>);
System.<span class="ST2">out</span>.println(list10);
<span class="comment">/*</span>
<span class="comment"> The disjoint(collection1, collection2) method returns true if the two collections</span>
<span class="comment"> have no elements in common. For example, in the following code, the disjoint(collection1,</span>
<span class="comment"> collectio2) returns false, but the disjoint(collection1, collection3) returns true.</span>
<span class="comment"> */</span>
System.<span class="ST2">out</span>.println(<span class="string">&quot;</span><span class="literal">\n</span><span class="string">Collections.disjoints()</span><span class="string">&quot;</span>);
Collection&lt;String&gt; collection1 = Arrays.<span class="ST3">asList</span>(<span class="string">&quot;</span><span class="string">red</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">cyan</span><span class="string">&quot;</span>);
Collection&lt;String&gt; collection2 = Arrays.<span class="ST3">asList</span>(<span class="string">&quot;</span><span class="string">red</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">blue</span><span class="string">&quot;</span>);
Collection&lt;String&gt; collection3 = Arrays.<span class="ST3">asList</span>(<span class="string">&quot;</span><span class="string">pink</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">tan</span><span class="string">&quot;</span>);
System.<span class="ST2">out</span>.println(Collections.<span class="ST3">disjoint</span>(collection1, collection2));
System.<span class="ST2">out</span>.println(Collections.<span class="ST3">disjoint</span>(collection1, collection3));
System.<span class="ST2">out</span>.println(<span class="string">&quot;</span><span class="literal">\n</span><span class="string">Frequency</span><span class="string">&quot;</span>);
Collection&lt;String&gt; collection = Arrays.<span class="ST3">asList</span>(<span class="string">&quot;</span><span class="string">red</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">cyan</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">red</span><span class="string">&quot;</span>);
System.<span class="ST2">out</span>.println(collection + <span class="string">&quot;</span><span class="string"> red occurs </span><span class="string">&quot;</span> + Collections.<span class="ST3">frequency</span>(collection, <span class="string">&quot;</span><span class="string">red</span><span class="string">&quot;</span>) + <span class="string">&quot;</span><span class="string"> times.</span><span class="string">&quot;</span>);
}
}
</pre></body>
</html>

@ -2,7 +2,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>edu.slcc.asdv.caleb</groupId>
<artifactId>JavaFXBallsWithComparator</artifactId>
<artifactId>lab7-chapter20_CalebFontenot</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

@ -14,28 +14,47 @@ import java.util.List;
* @author caleb
*/
public class A2 {
int x;
public A2() {}
public A2(int x) {this.x = x;}
public A2() {
}
public A2(int x) {
this.x = x;
}
@Override
public String toString()
{
public String toString() {
return "A2{" + "x=" + x + '}';
}
public static void main(String[] args)
{
System.out.println("Sorting in ascending order");
public static void main(String[] args) {
List<A2> list1 = Arrays.asList(new A2(4), new A2(), new A2(2));
Comparator<A2> c = new Comparator<A2>() {
@Override
public int compare(A2 o1, A2 o2)
{
return o1.x - o2.x;
public int compare(A2 o1, A2 o2) {
return o1.x - o2.x;
}
};
Comparator<A2> c2 = new Comparator<A2>() {
@Override
public int compare(A2 o1, A2 o2) {
int returnVal = 0;
if(o1.x > o2.x) {
returnVal = -1;
} else {
returnVal = 0;
}
return returnVal;
}
};
System.out.println("Sorting in ascending order");
Collections.sort(list1, c);
System.out.println(list1);
System.out.println("Sorting in desending order");
Collections.sort(list1,c2);
System.out.println(list1);
}
}

@ -0,0 +1,63 @@
/*
* 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.javafxballswithcomparator;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
*
* @author caleb
*/
public class A3 {
int x;
public A3() {
}
public A3(int x) {
this.x = x;
}
@Override
public String toString() {
return "A2{" + "x=" + x + '}';
}
public static Comparator<A3> comparator() {
Comparator<A3> c = new Comparator<A3>() {
@Override
public int compare(A3 o1, A3 o2) {
return o1.x - o2.x;
}
};
return c;
}
public static Comparator<A3> comparatorReverse() {
Comparator<A3> c = new Comparator<A3>() {
@Override
public int compare(A3 o1, A3 o2) {
return o1.x > o2.x ? -1 : 0;
}
};
return c;
}
public static void main(String[] args) {
List<A3> list1 = Arrays.asList(new A3(4), new A3(), new A3(2));
System.out.println("Sorting in ascending order");
Collections.sort(list1, A3.comparator());
System.out.println(list1);
System.out.println("Sorting in desending order");
Collections.sort(list1, A3.comparatorReverse());
System.out.println(list1);
}
}

@ -0,0 +1,80 @@
/*
* 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.javafxballswithcomparator;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
*
* @author caleb
*/
public class A4<E extends Comparable<E>> {
E x;
public A4() {}
public A4(E x) {this.x = x;}
public static Comparator<A4> comparator() {
Comparator<A4> c = new Comparator<A4>() {
@Override
public int compare(A4 o1, A4 o2) {
return o1.x.compareTo(o2.x);
}
};
return c;
}
public static Comparator<A4> comparatorReverse() {
Comparator<A4> c = new Comparator<A4>() {
@Override
public int compare(A4 o1, A4 o2) {
switch (o1.x.compareTo(o2.x)) {
case -1:
return 1;
case 0:
return 0;
case 1:
return -1;
}
return -112315234;
}
};
return c;
}
@Override
public String toString() {
return "A4{" + "x=" + x + '}';
}
public static void main(String[] args) {
System.out.println("Sorting in ascending order");
List<A4> list1 = Arrays.asList(
new A4(new Integer(4)),
new A4(new Integer(1)),
new A4(new Integer(2))
);
Collections.sort(list1, A4.comparator());
List<A4> list2 = Arrays.asList(
new A4(new String("once")),
new A4(new String("upon")),
new A4(new String("a")),
new A4(new String("time")),
new A4(new String("in")),
new A4(new String("America"))
);
Collections.sort(list2, A4.comparator());
System.out.println(list1);
System.out.println(list2);
System.out.println("Now, in descending order:");
Collections.sort(list2, A4.comparatorReverse());
System.out.println(list2);
}
}

@ -0,0 +1,40 @@
/*
* 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.javafxballswithcomparator;
import java.util.Collections;
import java.util.Comparator;
import java.util.PriorityQueue;
/**
*
* @author caleb
*/
public class TestPriorityQueue {
public static void main(String[] args) {
PriorityQueue<String> queue1 = new PriorityQueue<>();
queue1.offer("Oklahoma");
queue1.offer("Indiana");
queue1.offer("Georgia");
queue1.offer("Texas");
System.out.println("Priority queue using Comparable:");
while (queue1.size() > 0) {
System.out.print(queue1.remove() + " ");
}
Comparator<String> c = Collections.reverseOrder();
PriorityQueue<String> queue2 = new PriorityQueue<>(4, c);
queue2.offer("Oklahoma");
queue2.offer("Indiana");
queue2.offer("Georgia");
queue2.offer("Texas");
System.out.println("\n\nPriority queue is using Comparator: ");
while (queue2.size() > 0) {
System.out.print(queue2.remove() + " ");
}
}
}

@ -0,0 +1,100 @@
/*
* 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.javafxballswithcomparator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Random;
/**
*
* @author caleb
*/
public class TestTheCollections {
public static void main(String[] args) {
System.out.println("Sorting in ascending order");
List<String> list1 = Arrays.asList("red", "green", "blue");
Collections.sort(list1);
System.out.println(list1);
System.out.println("Sorting in descending order");
List<String> list2 = Arrays.asList("yellow", "red", "green", "blue");
Collections.sort(list2);
System.out.println(list2);
System.out.println("\nBinary Search");
List<Integer> list3
= Arrays.asList(2, 4, 7, 10, 11, 45, 50, 59, 60, 66);
System.out.println(list3 + " 7 is at index: " + Collections.binarySearch(list3, 7));
System.out.println(list3 + " 9 is at index: " + Collections.binarySearch(list3, 9));
System.out.println(list3 + " 100 is at index: " + Collections.binarySearch(list3, 100));
List<String> list4 = new ArrayList<>();
list4.addAll(list1);
System.out.println(list4 + " red is at index: " + Collections.binarySearch(list4, "red"));
System.out.println(list4 + " amber is at index: " + Collections.binarySearch(list4, "amber"));
System.out.println(list4 + " brown is at index: " + Collections.binarySearch(list4, "brown"));
System.out.println("\nReverse the list");
List<String> list5 = new ArrayList<>();
list5.addAll(list2);
System.out.println("Original list: " + list5);
Collections.reverse(list5);
System.out.println("Reversed list: " + list5);
System.out.println("\nShuffle lists");
List<String> list6 = new ArrayList<>();
List<String> list7 = new ArrayList<>();
list6.addAll(list2);
list7.addAll(list2);
System.out.println("Original list: " + list6);
Collections.shuffle(list6, new Random(20));
System.out.println("Shuffled list: " + list6);
System.out.println("Original list: " + list7);
Collections.shuffle(list7, new Random(20));
System.out.println("Shuffled list: " + list7);
List<String> list8 = new ArrayList<>();
list8.addAll(list2);
List<String> list9 = Arrays.asList("white", "black");
System.out.println("\nCopy into " + list8 + " the list " + list9);
Collections.copy(list8, list9);
System.out.println(list8);
System.out.println("The output for list 8 is [white, black, green, blue].\n"
+ "The copy method performs a \n"
+ "shallow copy: only the references of the elements fromt he source list are copied."
);
List<String> list10 = new ArrayList<>();
list10.addAll(list1);
System.out.println("\nFill the list " + list10 + " with \'black\'.");
Collections.fill(list10, "black");
System.out.println(list10);
/*
The disjoint(collection1, collection2) method returns true if the two collections
have no elements in common. For example, in the following code, the disjoint(collection1,
collectio2) returns false, but the disjoint(collection1, collection3) returns true.
*/
System.out.println("\nCollections.disjoints()");
Collection<String> collection1 = Arrays.asList("red", "cyan");
Collection<String> collection2 = Arrays.asList("red", "blue");
Collection<String> collection3 = Arrays.asList("pink", "tan");
System.out.println(Collections.disjoint(collection1, collection2));
System.out.println(Collections.disjoint(collection1, collection3));
System.out.println("\nFrequency");
Collection<String> collection = Arrays.asList("red", "cyan", "red");
System.out.println(collection + " red occurs " + Collections.frequency(collection, "red") + " times.");
}
}

@ -0,0 +1,24 @@
edu/slcc/asdv/caleb/javafxballswithcomparator/A4$1.class
edu/slcc/asdv/caleb/javafxballswithcomparator/GeometricObject.class
edu/slcc/asdv/caleb/javafxballswithcomparator/TestComparator.class
edu/slcc/asdv/caleb/javafxballswithcomparator/A2$2.class
edu/slcc/asdv/caleb/javafxballswithcomparator/MultipleBallsWithComparator$Ball.class
edu/slcc/asdv/caleb/javafxballswithcomparator/A3$1.class
edu/slcc/asdv/caleb/javafxballswithcomparator/A4$2.class
edu/slcc/asdv/caleb/javafxballswithcomparator/GeometricObjectComparator.class
edu/slcc/asdv/caleb/javafxballswithcomparator/TestArrayAndLinkedList.class
edu/slcc/asdv/caleb/javafxballswithcomparator/A2$1.class
edu/slcc/asdv/caleb/javafxballswithcomparator/MultipleBallsWithComparator$MultipleBallPane.class
edu/slcc/asdv/caleb/javafxballswithcomparator/Rectangle.class
edu/slcc/asdv/caleb/javafxballswithcomparator/App.class
edu/slcc/asdv/caleb/javafxballswithcomparator/A2.class
edu/slcc/asdv/caleb/javafxballswithcomparator/MultipleBallsWithComparator.class
module-info.class
edu/slcc/asdv/caleb/javafxballswithcomparator/A1.class
edu/slcc/asdv/caleb/javafxballswithcomparator/TestPriorityQueue.class
edu/slcc/asdv/caleb/javafxballswithcomparator/A3.class
edu/slcc/asdv/caleb/javafxballswithcomparator/Circle.class
edu/slcc/asdv/caleb/javafxballswithcomparator/SystemInfo.class
edu/slcc/asdv/caleb/javafxballswithcomparator/TestTheCollections.class
edu/slcc/asdv/caleb/javafxballswithcomparator/A3$2.class
edu/slcc/asdv/caleb/javafxballswithcomparator/A4.class

@ -0,0 +1,12 @@
/home/caleb/ASDV-Java/Semester 3/Assignments/JavaFXBallsWithComparator/src/main/java/edu/slcc/asdv/caleb/javafxballswithcomparator/Circle.java
/home/caleb/ASDV-Java/Semester 3/Assignments/JavaFXBallsWithComparator/src/main/java/edu/slcc/asdv/caleb/javafxballswithcomparator/Rectangle.java
/home/caleb/ASDV-Java/Semester 3/Assignments/JavaFXBallsWithComparator/src/main/java/edu/slcc/asdv/caleb/javafxballswithcomparator/TestArrayAndLinkedList.java
/home/caleb/ASDV-Java/Semester 3/Assignments/JavaFXBallsWithComparator/src/main/java/edu/slcc/asdv/caleb/javafxballswithcomparator/A1.java
/home/caleb/ASDV-Java/Semester 3/Assignments/JavaFXBallsWithComparator/src/main/java/module-info.java
/home/caleb/ASDV-Java/Semester 3/Assignments/JavaFXBallsWithComparator/src/main/java/edu/slcc/asdv/caleb/javafxballswithcomparator/GeometricObject.java
/home/caleb/ASDV-Java/Semester 3/Assignments/JavaFXBallsWithComparator/src/main/java/edu/slcc/asdv/caleb/javafxballswithcomparator/GeometricObjectComparator.java
/home/caleb/ASDV-Java/Semester 3/Assignments/JavaFXBallsWithComparator/src/main/java/edu/slcc/asdv/caleb/javafxballswithcomparator/A2.java
/home/caleb/ASDV-Java/Semester 3/Assignments/JavaFXBallsWithComparator/src/main/java/edu/slcc/asdv/caleb/javafxballswithcomparator/SystemInfo.java
/home/caleb/ASDV-Java/Semester 3/Assignments/JavaFXBallsWithComparator/src/main/java/edu/slcc/asdv/caleb/javafxballswithcomparator/App.java
/home/caleb/ASDV-Java/Semester 3/Assignments/JavaFXBallsWithComparator/src/main/java/edu/slcc/asdv/caleb/javafxballswithcomparator/MultipleBallsWithComparator.java
/home/caleb/ASDV-Java/Semester 3/Assignments/JavaFXBallsWithComparator/src/main/java/edu/slcc/asdv/caleb/javafxballswithcomparator/TestComparator.java

@ -13,6 +13,6 @@ You can copy and paste the single properties, into the pom.xml file and the IDE
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_20</netbeans.hint.jdkPlatform>
<netbeans.hint.jdkPlatform>Graal_JDK_20</netbeans.hint.jdkPlatform>
</properties>
</project-shared-configuration>

@ -7,8 +7,8 @@
<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>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<exec.mainClass>com.calebfontenot.mp4_generics_calebfontenot.MP4_Generics_CalebFontenot</exec.mainClass>
</properties>
</project>

@ -75,11 +75,16 @@ public class ArrayListASDV<E>
* @throws IllegalArgumentException - if some property of the element prevents it from being added to this collection
*/
@Override
public boolean add(E e)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
public boolean add(E e) {
if (e == null) {
throw new NullPointerException();
}
list[index++] = e;
if (index >= list.length * 0.75) {
doubleSizeOfList();
}
return true;
}
/**

@ -46,7 +46,7 @@ public class IteratorASDV<E> {
};
return (IteratorASDV<E>) it;
}
};
public static void main(String[] args)
{
IteratorASDV<Integer> ti = new IteratorASDV<Integer>();
@ -58,4 +58,5 @@ public class IteratorASDV<E> {
System.out.println(it.next());
}
}
}

@ -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>test</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>com.calebfontenot.test.Test</exec.mainClass>
</properties>
</project>

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