Initial Commit

This commit is contained in:
Isaac Shoebottom 2022-10-07 00:44:12 -03:00
commit 8ff85da81c
308 changed files with 10106 additions and 0 deletions

View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/../../../../../../../:\ProgrammingProjects\JavaProjects\JavaYear1\CS1083\Assignment 1\.idea/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

View File

@ -0,0 +1,7 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<ScalaCodeStyleSettings>
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
</ScalaCodeStyleSettings>
</code_scheme>
</component>

View File

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DiscordProjectSettings">
<option name="show" value="PROJECT" />
</component>
</project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Assignment 1.iml" filepath="$PROJECT_DIR$/Assignment 1.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/20.1.0/annotations-20.1.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>

View File

@ -0,0 +1,86 @@
/**
This class is the driver the program.
@author Isaac Shoebottom (3429069)
*/
public class Driver {
public static void main(String[] args) {
Vehicle vehicle1 = new Vehicle(2, 4, 450.45);
Vehicle vehicle2 = new Vehicle(2, 8, 636.30);
Vehicle vehicle3 = new Vehicle(4, 12, 4500);
Vehicle vehicle4 = new Vehicle(16, 4, 100);
Vehicle vehicle5 = new Vehicle(16, 40, 100);
Ferry ferry = new Ferry(3, 10, 16, 3333);
if (ferry.addVehicle(vehicle1)) {
System.out.println("Vehicle " + vehicle1.getUniqueID() + " added");
} else {
System.out.println("Couldn't add Vehicle " + vehicle1.getUniqueID());
}
if (ferry.addVehicle(vehicle1)) {
System.out.println("Vehicle " + vehicle1.getUniqueID() + " added!");
} else {
System.out.println("Couldn't add Vehicle " + vehicle1.getUniqueID());
}
if (ferry.addVehicle(vehicle2)) {
System.out.println("Vehicle " + vehicle2.getUniqueID() + " added!");
} else {
System.out.println("Couldn't add Vehicle " + vehicle2.getUniqueID());
}
if (ferry.addVehicle(vehicle3)) {
System.out.println("Vehicle " + vehicle3.getUniqueID() + " added!");
} else {
System.out.println("Couldn't add Vehicle " + vehicle3.getUniqueID());
}
if (ferry.addVehicle(vehicle3)) {
System.out.println("Vehicle " + vehicle3.getUniqueID() + " added!");
} else {
System.out.println("Couldn't add Vehicle " + vehicle3.getUniqueID());
}
if (ferry.addVehicle(vehicle4)) {
System.out.println("Vehicle " + vehicle4.getUniqueID() + " added!");
} else {
System.out.println("Couldn't add Vehicle " + vehicle4.getUniqueID());
}
if (ferry.addVehicle(vehicle5)) {
System.out.println("Vehicle " + vehicle5.getUniqueID() + " added!");
} else {
System.out.println("Couldn't add Vehicle " + vehicle5.getUniqueID());
}
if (ferry.removeVehicle(vehicle5)) {
System.out.println("Vehicle " + vehicle5.getUniqueID() + " removed!");
} else {
System.out.println("Couldn't remove Vehicle " + vehicle5.getUniqueID());
}
if (ferry.removeVehicle(vehicle2)) {
System.out.println("Vehicle " + vehicle2.getUniqueID() + " removed!");
} else {
System.out.println("Couldn't remove Vehicle " + vehicle2.getUniqueID());
}
if (ferry.changePassengersOnVehicle(vehicle1,7)) {
System.out.println("Vehicle " + vehicle1.getUniqueID() + " passenger's changed!");
} else {
System.out.println("Couldn't change passengers");
}
if (ferry.changePassengersOnVehicle(vehicle1, 69)) {
System.out.println("Vehicle " + vehicle1.getUniqueID() + " passenger's changed!");
} else {
System.out.println("Couldn't change passengers");
}
if (ferry.changePassengersOnVehicle(vehicle4, 30)) {
System.out.println("Vehicle " + vehicle5.getUniqueID() + " passenger's changed!");
} else {
System.out.println("Couldn't change passengers");
}
System.out.println(ferry.weightReport());
System.out.println(ferry.vehicleList());
}
}

View File

@ -0,0 +1,146 @@
/**
This class is the ferry object.
@author Isaac Shoebottom (3429069)
*/
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Objects;
public class Ferry {
int maximumNumberOfVehicles;
int maximumNumberOfAxles;
int maximumNumberOfPassengers;
double maxWeight;
int numberOfVehicles;
int numberOfAxles;
int numberOfPassengers;
double weight;
Vehicle[] vehicles = new Vehicle[0];
Ferry(int maximumNumberOfVehicles, int maximumNumberOfAxles, int maximumNumberOfPassengers, double maxWeight) {
this.maximumNumberOfVehicles = maximumNumberOfVehicles;
this.maximumNumberOfAxles = maximumNumberOfAxles;
this.maximumNumberOfPassengers = maximumNumberOfPassengers;
this.maxWeight = maxWeight;
}
public boolean addVehicle(Vehicle newVehicle) {
for(Vehicle vehicle: vehicles) {
if (newVehicle.getUniqueID() == vehicle.getUniqueID()) {
return false;
}
}
if (newVehicle.getWeight() + weight > maxWeight ||
newVehicle.getAxles() +numberOfAxles > maximumNumberOfAxles ||
newVehicle.getNumberOfPassengers() + numberOfPassengers > maximumNumberOfPassengers ||
1+numberOfVehicles > maximumNumberOfVehicles)
{
return false;
}
int counter = vehicles.length;
vehicles = Arrays.copyOf(vehicles, vehicles.length + 1);
vehicles[counter] = newVehicle;
addOrRemoveSpecs(newVehicle, 1);
return true;
}
/*
public boolean addVehicles(Vehicle... newVehicles) {
double[] vehicleInfo = calculateTotalSpecsForArray(newVehicles);
//axles = 1, passengers = 2, weight = 0, vehicles = 3
if (vehicleInfo[0] > maxWeight ||
vehicleInfo[1] > maximumNumberOfAxles ||
vehicleInfo[2] > maximumNumberOfPassengers ||
vehicleInfo[3] > maximumNumberOfVehicles ||
doIDsMatch(vehicles, newVehicles))
{
return false;
}
addOrRemoveSpecs(newVehicles, 1);
int counter = vehicles.length;
vehicles = Arrays.copyOf(vehicles, vehicles.length + newVehicles.length);
for (Vehicle vehicle: newVehicles) {
vehicles[counter] = vehicle;
}
return true;
}
*/
public boolean removeVehicle(Vehicle newVehicle) {
for (int i = 0; i < vehicles.length; i++) {
if (vehicles[i].getUniqueID() == newVehicle.getUniqueID()) {
vehicles[i] = null;
addOrRemoveSpecs(newVehicle, -1);
vehicles = Arrays.stream(vehicles).filter(Objects::nonNull).toArray(Vehicle[]::new);
return true;
}
}
return false;
}
public void addOrRemoveSpecs(Vehicle vehicle, int sign) {
numberOfVehicles += sign;
numberOfAxles += sign*vehicle.getAxles();
numberOfPassengers += sign*vehicle.getNumberOfPassengers();
weight += sign*vehicle.getWeight();
}
/*
private double[] calculateTotalSpecsForArray(Vehicle[] tempVehicles) {
double totalWeight = 0;
int totalAxles = 0;
int totalPassengers = 0;
int totalNumberOfCars = tempVehicles.length;
for (Vehicle vehicle: tempVehicles) {
totalWeight += vehicle.getWeight();
totalAxles += vehicle.getAxles();
totalPassengers += vehicle.getNumberOfPassengers();
}
return new double[]{totalWeight, totalAxles, totalPassengers, totalNumberOfCars};
}
private void addOrRemoveSpecs(Vehicle[] tempVehicles, int sign) {
double[] tempSpecs = calculateTotalSpecsForArray(tempVehicles);
numberOfAxles += sign*tempSpecs[1];
numberOfPassengers += sign*tempSpecs[2];
numberOfVehicles += sign*tempSpecs[3];
weight += sign*tempSpecs[0];
}
private boolean doIDsMatch(Vehicle[] existingVehicles, Vehicle[] newVehicles) {
for (Vehicle vehicle: existingVehicles) {
for (Vehicle newVehicle: newVehicles) {
if (vehicle.getUniqueID() == newVehicle.getUniqueID()) {
return true;
}
}
}
return false;
}
*/
public boolean changePassengersOnVehicle(Vehicle vehicle, int newNumberOfPassengers) {
if ((newNumberOfPassengers-vehicle.getNumberOfPassengers())+newNumberOfPassengers > maximumNumberOfPassengers) {
return false;
}
else {
vehicle.setNumberOfPassengers(newNumberOfPassengers);
numberOfPassengers += newNumberOfPassengers - vehicle.getNumberOfPassengers();
return true;
}
}
public String weightReport() {
return ("The weight left on the ferry is " + (maxWeight - weight) + " Kg");
}
public String vehicleList() {
String list = "";
DecimalFormat df = new DecimalFormat("00,000.00");
for(Vehicle vehicle: vehicles) {
String patternedWeight = df.format(vehicle.getWeight());
list += vehicle.getUniqueID() + "\t" + patternedWeight + " kg\n";
}
list+= "Total Weight:\t" + weight + "\n";
list+= "Total Axles:\t" + numberOfAxles + "\n";
list+= "Total Passengers:\t" + numberOfPassengers+ "\n";
return list;
}
}

View File

@ -0,0 +1,38 @@
/**
This class is the vehicle object.
@author Isaac Shoebottom (3429069)
*/
public class Vehicle {
private static long uniqueIDTracker = 100;
private final long uniqueID;
private int numberOfPassengers;
private final int axles;
private final double weight;
Vehicle(int numberOfPassengers, int wheels,double weight ) {
this.weight = weight;
this.axles = (wheels > 2) ? wheels/2 : 0;
this.numberOfPassengers = numberOfPassengers;
uniqueID = uniqueIDTracker + 1;
uniqueIDTracker++;
}
public double getWeight() {
return weight;
}
public int getAxles() {
return axles;
}
public int getNumberOfPassengers() {
return numberOfPassengers;
}
public long getUniqueID() {
return uniqueID;
}
public void setNumberOfPassengers(int numberOfPassengers) {
this.numberOfPassengers = numberOfPassengers;
}
}

View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/../../../../../../../:\ProgrammingProjects\JavaProjects\JavaYear1\CS1083\Assignment 10\.idea/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

View File

@ -0,0 +1,7 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<ScalaCodeStyleSettings>
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
</ScalaCodeStyleSettings>
</code_scheme>
</component>

View File

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DiscordProjectSettings">
<option name="show" value="PROJECT_FILES" />
</component>
</project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Assignment 10.iml" filepath="$PROJECT_DIR$/Assignment 10.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,6 @@
[a, a (100), a, a (101), a, a (102), After, Student (1), After, Student (1), After, Student (9999999), One, Student (1), Shoebottom, Isaac (3429063), Shoebottom, Isaac (3429069)]
[a, a (101), a, a (102), After, Student (1), After, Student (9999999), One, Student (1), Shoebottom, Isaac (3429063)]
[Zzzzz, Zzzzz (100000000), Test, Adam (89), Shoebottom, Isaac (3429063), One, Student (1), Gorsk, Lam (8990), After, Student (9999999), After, Student (1), a, a (102), a, a (101)]
There was no such student in the list
[a, a (101), a, a (102), After, Student (1), After, Student (9999999), Gorsk, Lam (8990), One, Student (1), Shoebottom, Isaac (3429063), Test, Adam (89), Zzzzz, Zzzzz (100000000)]
9

View File

@ -0,0 +1,170 @@
import java.util.NoSuchElementException;
/**
* Note: when implementing this doubly linked list, I though of "end" to be the end as in it is similar to a stack
* and front refers to the top element (or the first). The name might not be the most sensible if you think of the front
* like like front of the linked list, but the code works.
* @author Isaac Shoebottom (3429069)
*/
public class ClassList {
/**
* The bottom element of the linked list
*/
private StudentNode end;
/**
* The top element of the linked list
*/
private StudentNode front;
/**
* The size of the linked list.
*/
private int size;
/**
* Method to add a student to the linked list in sorted order
* @param studentIn The student ot be added.
*/
public void add(Student studentIn) {
StudentNode newNode = new StudentNode(studentIn);
if (end == null) {
end = newNode;
front = newNode;
}
else if(newNode.data.compareTo(end.data) <= 0) {
newNode.next = end;
end.prev = newNode;
end = newNode;
}
else if(newNode.data.compareTo(front.data) >= 0) {
newNode.prev = front;
front.next = newNode;
front = newNode;
}
else {
StudentNode current = end;
while (newNode.data.compareTo(current.data) > 0) {
if (current != front)
current = current.next;
else {
break;
}
}
newNode.next = current;
newNode.prev = current.prev;
current.prev.next = newNode;
current.prev = newNode;
}
size++;
}
/**
* Method to get the size of the linked list, also known as the number of students
* @return The size of the linked list
*/
public int getNumStudents() {
return size;
}
/**
* Method to get a reversed list in array form.
* @return The reversed array representation of the linked list
*/
public Student[] getReversedList() {
Student[] students = new Student[size];
StudentNode current = front;
for(int i = 0; i < size; i++) {
students[i] = current.data;
current = current.prev;
}
return students;
}
/**
* Method to remove a student from the linked list
* @param studentOut The student to be removed
* @throws NoSuchElementException When the student is not found
*/
public void remove(Student studentOut) throws NoSuchElementException {
if(studentOut.compareTo(end.data) == 0) {
end = end.next;
size--;
return;
}
else if(studentOut.compareTo(front.data) == 0) {
front = front.prev;
size--;
return;
}
else {
StudentNode current = end;
for (int i = 0; i < size; i++) {
if (current.data.compareTo(studentOut) == 0) {
current.prev.next = current.next;
current.next.prev = current.prev;
size--;
return;
}
current = current.next;
}
}
throw new NoSuchElementException("There was no such student in the list");
}
/**
* Method to represent the contents of the linked list
* @return A string representing the linked list
*/
public String toString() {
StringBuilder str = new StringBuilder("[");
StudentNode current = end;
for (int i = 0; i < size; i++) {
str.append(current.data.toString()).append(", ");
current = current.next;
}
str = new StringBuilder(str.substring(0, str.length() - 2));
str.append("]");
return str.toString();
}
/**
* A node representation of a student, containing the next and previous student
* @author Isaac Shoebottom (3429069)
*/
public static class StudentNode {
/**
* The data Student object contained in the node
*/
Student data;
/**
* The next student node in the chain
*/
StudentNode next;
/**
* The previous student node in the chain
*/
StudentNode prev;
/**
* The constructor for the student node
* @param dataIn Takes in a student object
*/
StudentNode(Student dataIn) {
data = dataIn;
next = null;
prev = null;
}
/**
* Returns what the student node contains for data
* @return The data contained within the student node
*/
@Override
public String toString() {
return data.toString();
}
}
}

View File

@ -0,0 +1,70 @@
import java.util.NoSuchElementException;
/**
* Driver for the linked list
* @author Isaac Shoebottom (3429069)
*/
public class LinkedListDriver {
@SuppressWarnings("SpellCheckingInspection")
public static void main(String[] args) {
Student isaac = new Student("Isaac", "Shoebottom", 3429069);
Student studentOne = new Student("Student", "One", 1);
Student studentAfterMe = new Student("Student", "After", 9999999);
Student test1 = new Student("Isaac", "Shoebottom", 3429063);
Student test2 = new Student("Student", "After", 1);
Student sequence1 = new Student("a", "a", 100);
Student sequence2 = new Student("a", "a", 102);
Student sequence3 = new Student("a", "a", 101);
Student test3 = new Student("Adam", "Test", 89);
Student test4 = new Student("Lam", "Gorsk", 8990);
Student test5 = new Student("Zzzzz", "Zzzzz", 100000000);
ClassList classList = new ClassList();
classList.add(isaac);
classList.add(studentOne);
classList.add(studentAfterMe);
classList.add(test1);
classList.add(test2);
classList.add(test2);
classList.add(sequence1);
classList.add(sequence2);
classList.add(sequence3);
System.out.println(classList.toString());
classList.remove(isaac);
classList.remove(test2);
classList.remove(sequence1);
System.out.println(classList.toString());
classList.add(test3);
classList.add(test4);
classList.add(test5);
//would this be allowed?
//System.out.println(Arrays.toString(classList.getReversedList()));
StringBuilder reversedList = new StringBuilder("[");
Student[] students = classList.getReversedList();
for(int i = 0; i < classList.getNumStudents(); i++) {
reversedList.append(students[i].toString()).append(", ");
}
reversedList = new StringBuilder(reversedList.substring(0, reversedList.length() - 2));
reversedList.append("]");
System.out.println(reversedList);
try {
classList.remove(isaac);
}catch (NoSuchElementException exception) {
System.out.println(exception.getMessage());
}
System.out.println(classList.toString());
System.out.println(classList.getNumStudents());
}
}

View File

@ -0,0 +1,66 @@
/**
* Represents a student.
* @author Isaac Shoebottom (3429069)
*/
public class Student implements Comparable<Student>{
/**
The last name of the student.
*/
private final String lastName;
/**
The first name of the student.
*/
private final String firstName;
/**
The student's ID number.
*/
private final long id;
/**
Constructs a student given their first and last name, and student ID.
@param firstNameIn The first name of the student.
@param lastNameIn The last name of the student.
@param idIn The student's ID number.
*/
public Student(String firstNameIn, String lastNameIn, int idIn){
firstName = firstNameIn;
lastName = lastNameIn;
id = idIn;
}
/**
Prints all the information about the student.
@return The student's information.
*/
public String toString(){
return lastName + ", " + firstName + " (" + id + ")";
}
/**
* CompareTo method compares the two students on last name, then first name, and then on id
* if lastname/firstname is lexicographically greater than o.lastname return positive int
* we return a positive int when the student o is less than the current object
* we want id's to be sorted smallest to largest so an object is greater when it's id is greater
* @param o The student being taken in
* @return 0 if students are equal, 1 if the student being taken in is lesser, and -1 if the student being taken in is greater.
*/
@Override
public int compareTo(Student o) {
if (lastName.compareToIgnoreCase(o.lastName) > 0)
return 1;
if (lastName.compareToIgnoreCase(o.lastName) < 0)
return -1;
if (firstName.compareToIgnoreCase(o.firstName) > 0)
return 1;
if (firstName.compareToIgnoreCase(o.firstName) < 0)
return -1;
return Long.compare(id, o.id);
}
}

View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/../../../../../../../:\ProgrammingProjects\JavaProjects\JavaYear1\CS1083\Assignment 11\.idea/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

View File

@ -0,0 +1,7 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<ScalaCodeStyleSettings>
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
</ScalaCodeStyleSettings>
</code_scheme>
</component>

View File

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DiscordProjectSettings">
<option name="show" value="PROJECT_FILES" />
</component>
</project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Assignment 11.iml" filepath="$PROJECT_DIR$/Assignment 11.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,6 @@
Elizabeth Anne Flynn
Sarah Blair
Abe Corey
Blair Elliot
COREY FLYNN
anne blair

View File

@ -0,0 +1 @@
Elizabeth

View File

@ -0,0 +1,10 @@
Elizabeth Anne Flynn
Sarah Blair
Abe Corey
Blair Elliot
COREY FLYNN
anne blair
isaac ray avery
spencer adam
genna
Abcde

View File

@ -0,0 +1,23 @@
import java.io.*;
public class NameCountDriver{
public static void main(String[] args){
if(args.length < 1){
System.out.println("Usage: java CharCountDriver file");
return;
}
try{
NameCountTree tree = new NameCountTree();
tree.readText(args[0]);
tree.print();
System.out.println("Minimum entry in tree: ");
tree.printMin();
}
catch(IOException e){
System.out.println("Unable to read file");
}
}
}

View File

@ -0,0 +1,159 @@
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
/**
* Class that represents a binary tree of names sorted alphabetically
* @author Isaac Shoebottom (3429069)
*/
public class NameCountTree {
/**
* Root node, one at the top of the binary tree
*/
private Node root;
/**
* Public method for initiating addition to the tree
* @param valueIn String which represents the name
*/
public void add(String valueIn) {
if (root == null) {
root = new Node(new Pair(valueIn));
}
else {
add(valueIn, root);
}
}
/**
* Private method that recursively adds to the tree
* @param valueIn String that represents the name
* @param root The node that should be the new root for searching where to add the new node
*/
private void add(String valueIn, Node root) {
if (valueIn.equalsIgnoreCase(root.info.name)) {
root.info.count++;
}
else if (valueIn.compareToIgnoreCase(root.info.name) < 0) {
if (root.left == null) {
root.left = new Node(new Pair(valueIn));
}
else {
add(valueIn, root.left);
}
}
else {
if (root.right == null) {
root.right = new Node(new Pair(valueIn));
}
else {
add(valueIn, root.right);
}
}
}
/**
* Method for reading the input from a file
* @param filename String The name of the file to be read
* @throws IOException If the file does not exist
*/
public void readText(String filename) throws IOException {
Scanner sc = new Scanner(new File(filename));
while (sc.hasNext()) {
add(sc.next().toLowerCase());
}
}
/**
* Method to initiate a print of the tree
*/
public void print() {
print(root);
}
/**
* Private method that recursively prints the tree. Relies on that the tree is sorted alphabetically already
* @param root The node that is to be treated as root
*/
private void print(Node root) {
if (root != null) {
print(root.left);
System.out.println(root.info.toString());
print(root.right);
}
}
/**
* Method to print the smallest node alphabetically
*/
public void printMin() {
//in case of empty file
if (root != null) {
Node temp = root;
while (temp.left != null) {
temp = temp.left;
}
System.out.print(temp.info.toString());
}
}
/**
* Node class represents a node containing the left right and pair of information
*/
static class Node {
/**
* The left node to current node
*/
private Node left;
/**
* The right node to current node
*/
private Node right;
/**
* The info in the current node
*/
private final Pair info;
/**
* The constructor for a node
* @param info Takes in a pair and constructs a node out of it
*/
Node (Pair info) {
this.info = info;
}
}
/**
* Class that represents a pair of data, the name and count of how many of that name in the tree
*/
static private class Pair {
/**
* The name in the pair
*/
private final String name;
/**
* The count of how many of that name are in the tree
*/
private int count = 1;
/**
* The constructor for the pair
* @param name String of the name of the pair
*/
Pair(String name) {
this.name = name;
}
/**
* Reimplementation of toString to not reference the memory pointer but the contents of the class
* @return The string containing the name and count
*/
public String toString(){
return "(" + name + ", " + count + ")";
}
}
}

View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/../../../../../../../:\ProgrammingProjects\JavaProjects\JavaYear1\CS1083\Assignment 2\.idea/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

View File

@ -0,0 +1,7 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<ScalaCodeStyleSettings>
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
</ScalaCodeStyleSettings>
</code_scheme>
</component>

View File

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DiscordProjectSettings">
<option name="show" value="PROJECT_FILES" />
</component>
</project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Assignment 2.iml" filepath="$PROJECT_DIR$/Assignment 2.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,11 @@
5
9780006716693,The Last Battle,Lewis,2
9780007591855,The Silmarillion,Tolkien,3
9780048232298,The Lord of the Rings,Tolkien,1
9780385491037,The Robber Bride,Atwood,3
9781400079179,The Da Vinci Code,Brown,2
3
9780048232298,The Lord of the Rings,Tolkien,1
9780062230621,The Confidence Code,Kay,0
9780385491037,The Robber Bride,Atwood,3
9780071079170,The Skin We're In,Cole,5

View File

@ -0,0 +1,12 @@
5
9780006716693,The Last Battle,Lewis,2
9780007591855,The Silmarillion,Tolkien,3
9780048232298,The Lord of the Rings,Tolkien,1
9780385491037,The Robber Bride,Atwood,3
9781400079179,The Da Vinci Code,Brown,2
4
9780048232298,The Lord of the Rings,Tolkien,1
9780062230621,The Confidence Code,Kay,0
9780385491037,The Robber Bride,Atwood,3
9780007591855,The Silmarillion,Tolkien,3
9780071079170,The Skin We're In,Cole,5

View File

@ -0,0 +1,13 @@
6
9780006716693,The Last Battle,Lewis,2
9780007591855,The Silmarillion,Tolkien,3
9780048232298,The Lord of the Rings,Tolkien,1
9780385491037,The Robber Bride,Atwood,3
9781400079179,The Da Vinci Code,Brown,2
9780062230621,The Confidence Code,Kay,0
4
9780048232298,The Lord of the Rings,Tolkien,1
9780062230621,The Confidence Code,Kay,0
9780385491037,The Robber Bride,Atwood,3
9780007591855,The Silmarillion,Tolkien,3
9780071079170,The Skin We're In,Cole,5

View File

@ -0,0 +1,15 @@
6
9780006716693,The Last Battle,Lewis,2
9780007591855,The Silmarillion,Tolkien,3
9780048232298,The Lord of the Rings,Tolkien,1
9780385491037,The Robber Bride,Atwood,3
9781400079179,The Da Vinci Code,Brown,2
9780062230621,The Confidence Code,Kay,0
6
9780006716693,The Last Battle,Lewis,2
9780007591855,The Silmarillion,Tolkien,3
9780048232298,The Lord of the Rings,Tolkien,1
9780385491037,The Robber Bride,Atwood,3
9781400079179,The Da Vinci Code,Brown,2
9780062230621,The Confidence Code,Kay,0
9780071079170,The Skin We're In,Cole,5

View File

@ -0,0 +1,9 @@
5
9780006716693,The Last Battle,Lewis,2
9780007591855,The Silmarillion,Tolkien,3
9780048232298,The Lord of the Rings,Tolkien,1
9780385491037,The Robber Bride,Atwood,3
9781400079179,The Da Vinci Code,Brown,2
1
9780062230621,The Confidence Code,Kay,0
9780071079170,The Skin We're In,Cole,5

View File

@ -0,0 +1,87 @@
/**
Represents a Book in a personal library
@author L Bidlake
*/
public class Book{
/**
The ISBN of the book
*/
private final long ISBN;
/**
The title of the book
*/
private final String TITLE;
/**
The author of the book
*/
private final String AUTHOR;
/**
The number of times the book has been read
*/
private int read;
/**
Constructs a book with the specifice ISBN, title and author.
@param isbn The ISBN of the book.
@param title The title of the book.
@param author The author of the book.
@param read The number of times the book has been read.
*/
public Book(long isbn, String title, String author, int read){
ISBN = isbn;
TITLE = title;
AUTHOR = author;
this.read = read;
}
/**
This method returns the ISBN of the book.
@return The ISBN of the book.
*/
public long getIsbn(){
return ISBN;
}
/**
This method returns the title of the book.
@return The title of the book.
*/
public String getTitle(){
return TITLE;
}
/**
This method returns the author of the book.
@return The author of the book.
*/
public String getAuthor(){
return AUTHOR;
}
/**
This method returns the number of times the book has been read.
@return The number of times the book has been read.
*/
public int getRead(){
return read;
}
/**
This method changes the number of times the book has been read.
@param readIn The number of times the book has been read.
*/
public void setRead(int readIn){
read = readIn;
}
}

View File

@ -0,0 +1,149 @@
import java.util.Scanner;
/**
Represents a personal library.
@author L Bidlake, Isaac Shoebottom (3429069)
*/
public class Library{
/**
A collection of books.
*/
private Book[] library;
/**
Constructs a library with the specified collection of books.
@param library A collection of books.
*/
public Library(Book[] library){
this.library = library;
}
/**
Constructs a library by reading in the specified input.
@param scanIn Input containing a list of books.
*/
public Library(Scanner scanIn){
library = new Book[scanIn.nextInt()];
scanIn.nextLine();
for(int i = 0; i < library.length; i++){
Scanner scan = new Scanner(scanIn.nextLine());
scan.useDelimiter(",");
long isbn = scan.nextLong();
String title = scan.next();
String author = scan.next();
int read = scan.nextInt();
library[i] = new Book(isbn, title, author, read);
}
//makes sure the list is sorted after adding from entry.
bubbleSort(library);
}
/**
This method determines how many books occur in one library and
not the other
@param other Other library to compare books in this library.
@return The number of unique books.
*/
public int findUnique(Library other){
int counter = 0;
counter += countUniques(library, other.library);
counter += countUniques(other.library, library);
return counter;
}
/**
* Counts the uniques on one side of an array
* @param arr1 The first array, the one that the uniques are counted up against
* @param arr2 The second array, the array that the first array is compared against
* @return Integer of unique books
*/
public static int countUniques(Book[] arr1, Book[] arr2) {
int counter = 0;
boolean isUnique;
for (Book book1 : arr1) {
isUnique = true;
for (Book book2 : arr2) {
if (book1.getIsbn() < book2.getIsbn())
break;
if (book1.getIsbn() == book2.getIsbn()) {
isUnique = false;
break;
}
}
if (isUnique) {
counter++;
}
}
return counter;
}
/**
This method merges two libraries (includes both if duplicates).
@param other Library to merge with this library.
@return The library containing all contents of both libraries.
*/
public Library merge(Library other){
Book[] tempLibrary = new Book[library.length+other.library.length];
System.arraycopy(library, 0, tempLibrary, 0, library.length);
System.arraycopy(other.library, 0, tempLibrary, library.length, other.library.length);
bubbleSort(tempLibrary);
return new Library(tempLibrary);
}
/**
* Sorting algorithm of the bubble variety (in place sort)
* @param arr Array to be sorted
*/
public static void bubbleSort(Book[] arr) {
int length = arr.length;
for (int i = 0; i < length-1; i++)
for (int j = 0; j < length-i-1; j++)
if (arr[j].getIsbn() > arr[j+1].getIsbn()) {
Book temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
/**
This method add a book in sorted order by ISBN to this library.
@param bookIn The book to be added to this library in sorted order.
*/
public void addBook(Book bookIn){
int counter = 0;
for (Book book: library) {
if (book.getIsbn() <= bookIn.getIsbn()) {
counter++;
}
else {
break;
}
}
Book[] tempLibrary = new Book[library.length+1];
System.arraycopy(library, 0, tempLibrary, 0, counter);
tempLibrary[counter] = bookIn;
System.arraycopy(library, counter, tempLibrary, counter+1, (library.length-counter));
library = tempLibrary;
}
/**
Creates a formated print out of the library.
@return Formatted print out of the library.
*/
public String toString(){
String result = "";
for(int i = 0; i < library.length; i++){
result += library[i].getIsbn() + "\t" +
library[i].getTitle() + "\t" +
library[i].getAuthor() + "\t" +
library[i].getRead() + "\n";
}
return result;
}
}

View File

@ -0,0 +1,39 @@
import java.util.Scanner;
/**
Driver to test the Library class.
@author L Bidlake
*/
public class TestLibrary{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
Library myLibrary = new Library(scan);
Library yourLibrary = new Library(scan);
Scanner sc = new Scanner(scan.nextLine());
sc.useDelimiter(",");
long isbn = sc.nextLong();
String title = sc.next();
String author = sc.next();
int read = sc.nextInt();
Book bookToAdd = new Book(isbn, title, author, read);
System.out.println(myLibrary);
System.out.println(yourLibrary);
System.out.println("Number of unique books: " +
myLibrary.findUnique(yourLibrary));
myLibrary.addBook(bookToAdd);
System.out.println("My Library after adding a book: \n" +
myLibrary);
System.out.println("Merged Libraries: ");
System.out.println(myLibrary.merge(yourLibrary));
}
}

View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/../../../../../../../:\ProgrammingProjects\JavaProjects\JavaYear1\CS1083\Assignment 3\.idea/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

View File

@ -0,0 +1,7 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<ScalaCodeStyleSettings>
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
</ScalaCodeStyleSettings>
</code_scheme>
</component>

View File

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>

View File

@ -0,0 +1 @@
<html>Simple <b>Java</b> application that includes a class with <code>main()</code> method</html>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DiscordProjectSettings">
<option name="show" value="PROJECT_FILES" />
</component>
</project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectKey">
<option name="state" value="project://e2804f05-5315-4fc6-a121-c522a6c26470" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Assignment 3.iml" filepath="$PROJECT_DIR$/Assignment 3.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,3 @@
<template>
<input-field default="com.company">IJ_BASE_PACKAGE</input-field>
</template>

View File

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,5 @@
cA.equals(cB): true
cA.equals(cC): false
cA.equals(cD): false
cA.equals(sA): false
tA.equals(sA): false

View File

@ -0,0 +1,4 @@
cA.equals(cB): true
cA.equals(cC): false
cA.equals(sA): false
tA.equals(sA): false

View File

@ -0,0 +1,14 @@
1.0
1.0
0.6666666666666666
1.2732395447351628
1.0
3.464101615137755
[Equilateral Triangle: Length: 2.0]
true
false
1
cA.equals(cB): true
cA.equals(cC): false
cA.equals(sA): false
tA.equals(sA): false

View File

@ -0,0 +1,8 @@
2
true
false
[Cat: name: Penny]
1
false
true
[Cat: name: Zelly]

View File

@ -0,0 +1,42 @@
/**
* Cat class
* @author Isaac Shoebottom (3429069)
*/
public class Cat implements Comparable<Cat>{
String name;
double weight;
/**
* Cat object
* @param name The name of the cat
* @param weight The weight of the cat
*/
Cat(String name, double weight) {
this.name = name;
this.weight = weight;
}
/**
* For output to console
* @return The name of the object
*/
public String toString(){
return "[Cat: name: "+name+"]";
}
/**
* Compares cat objects
* @param obj Input cat object
* @return The cat that is greater, -1, 0, 1
*/
@Override
public int compareTo(Cat obj) {
if(name.compareTo(obj.name) > 0)
return 1;
else if(name.compareTo(obj.name) < 0)
return -1;
else return Double.compare(obj.weight, weight);
}
}

View File

@ -0,0 +1,22 @@
public class Circle extends Shape{
private double radius;
public Circle(double radiusIn){
radius = radiusIn;
}
public String toString(){
return "[Circle: radius: "+radius+"]";
}
public double getArea(){
return Math.PI*radius*radius;
}
public double getPerimeter(){
return Math.PI*2*radius;
}
}//End class Circle

View File

@ -0,0 +1,23 @@
public class EquilTriangle extends Shape{
private double length;
public EquilTriangle(double lengthIn){
length = lengthIn;
}
public String toString(){
return "[Equilateral Triangle: Length: "+length+"]";
}
public double getArea(){
double h = length;
double o = length/2;
return Math.sqrt(h*h-o*o);
}
public double getPerimeter(){
return length*3;
}
}//End class EquilTriangle

View File

@ -0,0 +1,65 @@
/**
* Find class
* @author Isaac Shoebottom (3429069)
*/
public class Find<T extends Comparable<T>> {
/**
* Gets the largest object in an array
* @param a The input array of objects
* @return The largest object
*/
public T getLargest(T[] a) {
int index = 0;
for (int i = 1; i < a.length; i++) {
if (a[i].compareTo(a[i - 1]) > 0) {
index = i;
}
}
return a[index];
}
/**
* Checks if an object is present in an array
* @param a The array to be checked against
* @param key The object that will be checked to be in the array
* @return Boolean true or false if in the array
*/
public boolean isPresent(T[] a, T key) {
for(T obj: a) {
if (obj.compareTo(key) == 0)
return true;
}
return false;
}
/**
* Checks how many times an object of the same perimeter/area is in the array
* @param a The array to be checked against
* @param key The object that will be counted
* @return The number of times it has been counted
*/
public int presentNTimes(T[] a, T key) {
int counter = 0;
for(T obj: a) {
if (obj.compareTo(key) == 0)
counter++;
}
return counter;
}
/**
* Checks if the array is sorted in accending order
* @param a The array to be checked
* @return Boolean true or false if it is sorted
*/
public boolean isSorted(T[] a) {
for (int i = 1; i < a.length; i++) {
if (a[i].compareTo(a[i - 1]) < 0) {
return false;
}
}
return true;
}
}

View File

@ -0,0 +1,39 @@
/**
* Shape class
* @author Isaac Shoebottom (3429069)
*/
public abstract class Shape implements Comparable<Shape>{
public abstract double getArea();
public abstract double getPerimeter();
public boolean equalsArea(Circle obj){
return obj.getArea() == getArea();
}
public boolean equalsArea(Square obj){
return obj.getArea() == getArea();
}
public boolean equalsArea(EquilTriangle obj){
return obj.getArea() == getArea();
}
/**
* Compares all shapes. Shapes must have a getPerimeter and a getArea method
* @param o Input object
* @return Integer -1, 0, 1
*/
@Override
public int compareTo(Shape o) {
double selfPerimeterArea = getPerimeter()/getArea();
double objPerimeterArea = o.getPerimeter()/o.getArea();
int returnValue = 0;
if (selfPerimeterArea > objPerimeterArea)
returnValue = 1;
else if (selfPerimeterArea < objPerimeterArea)
returnValue = -1;
return returnValue;
}
}//End class Shape

View File

@ -0,0 +1,21 @@
public class Square extends Shape{
private double length;
public Square(double lengthIn){
length = lengthIn;
}
public String toString(){
return "[Square: Length: "+length+"]";
}
public double getArea(){
return length*length;
}
public double getPerimeter(){
return 4*length;
}
}//End class Square

View File

@ -0,0 +1,27 @@
/**
* Test1
* @author Isaac Shoebottom (3429069)
*/
public class Test1
{
public static void main(String[] args){
// Create several shapes with two that
// have the same perimeter and two references
// that share the same object.
Circle cA = new Circle(2);
Circle cB = cA;
Circle cC = new Circle(2);
Circle cD = new Circle(3);
Square sA = new Square(Math.PI);
EquilTriangle tA= new EquilTriangle(2);
System.out.println("cA.equals(cB): "+cA.equals(cB) );
System.out.println("cA.equals(cC): "+cA.equals(cC) );
System.out.println("cA.equals(cD): "+cA.equals(cD) );
System.out.println("cA.equals(sA): "+cA.equals(sA) );
System.out.println("tA.equals(sA): "+tA.equals(sA) );
}
}//End Test1

View File

@ -0,0 +1,22 @@
public class Test1Extra
{
public static void main(String[] args){
// Create several shapes with two that
// have the same perimeter and two references
// that share the same object.
Circle cA = new Circle(2);
Circle cB = cA;
Circle cC = new Circle(2);
Circle cD = new Circle(3);
Square sA = new Square(Math.PI);
EquilTriangle tA= new EquilTriangle(2);
System.out.println("cA.equals(cB): "+cA.equalsArea(cB) );
System.out.println("cA.equals(cC): "+cA.equalsArea(cC) );
System.out.println("cA.equals(cD): "+cA.equalsArea(cD) );
System.out.println("cA.equals(sA): "+cA.equalsArea(sA) );
System.out.println("tA.equals(sA): "+tA.equalsArea(sA) );
}
}//End Test1

View File

@ -0,0 +1,26 @@
/**
* Test2
* @author Isaac Shoebottom (3429069)
*/
public class Test2
{
public static void main(String[] args){
// Create several shapes with two that
// have the same perimeter and two references
// that share the same object.
Circle cA = new Circle(2);
Circle cB = new Circle(2);
Circle cC = new Circle(3);
Square sA = new Square(Math.PI);
EquilTriangle tA = new EquilTriangle(2);
System.out.println("cA.equals(cB): "+cA.equalsArea(cB) );
System.out.println("cA.equals(cC): "+cA.equalsArea(cC) );
System.out.println("cA.equals(sA): "+cA.equalsArea(sA) );
System.out.println("tA.equals(sA): "+tA.equalsArea(sA) );
}
}//End Test2

View File

@ -0,0 +1,35 @@
/**
* Test3
* @author Isaac Shoebottom (3429069)
*/
public class Test3
{
public static void main(String[] args){
// Create several shapes with two that
// have the same perimeter and two references
// that share the same object.
Circle cA = new Circle(2);
Circle cB = new Circle(2);
Circle cC = new Circle(3);
Square sA = new Square(Math.PI);
Square sB = new Square(4);
EquilTriangle tA = new EquilTriangle(2);
Shape[] shapes = {cA, cB, cC, sA, sB, tA};
Find<Shape> find = new Find<>();
System.out.println(find.getLargest(shapes));
System.out.println(find.isPresent(shapes, sB));
System.out.println(find.isSorted(shapes));
System.out.println(find.presentNTimes(shapes, sA));
System.out.println("cA.equals(cB): "+cA.equalsArea(cB) );
System.out.println("cA.equals(cC): "+cA.equalsArea(cC) );
System.out.println("cA.equals(sA): "+cA.equalsArea(sA) );
System.out.println("tA.equals(sA): "+tA.equalsArea(sA) );
}
}//End Test3

View File

@ -0,0 +1,32 @@
/**
* Test4
* @author Isaac Shoebottom (3429069)
*/
public class Test4
{
public static void main(String[] args){
Cat cat1 = new Cat("Nelly", 18);
Cat cat2 = new Cat("Yenny", 9);
Cat cat3 = new Cat("Zelly", 7);
Cat cat4 = new Cat("Kitty", 6);
Cat cat5 = new Cat("Penny", 10);
Cat cat6 = new Cat("Kitty", 6);
Cat[] cats1 = {cat1, cat2, cat3};
Cat[] cats2 = {cat4, cat5, cat6};
Find<Cat> find = new Find<>();
System.out.println(find.presentNTimes(cats2, cat6));
System.out.println(find.isPresent(cats2, cat5));
System.out.println(find.isSorted(cats2));
System.out.println(find.getLargest(cats2));
System.out.println(find.presentNTimes(cats1, cat2));
System.out.println(find.isPresent(cats1, cat4));
System.out.println(find.isSorted(cats1));
System.out.println(find.getLargest(cats1));
}
}//End Test4

View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/../../../../../../../:\ProgrammingProjects\JavaProjects\JavaYear1\CS1083\Assignment 4\.idea/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

Some files were not shown because too many files have changed in this diff Show More