Initial Commit

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

8
Source Code/Assignment 3/.idea/.gitignore generated vendored Normal file
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>

9
Source Code/Assignment 3/.idea/misc.xml generated Normal file
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