aboutsummaryrefslogtreecommitdiffstats
path: root/csci1913/Java
diff options
context:
space:
mode:
authorRossTheRoss <msattr@gmail.com>2019-11-24 13:28:04 -0600
committerRossTheRoss <msattr@gmail.com>2019-11-24 13:28:04 -0600
commit3a19175f16f28eea198a85d3e25eee672832b7ea (patch)
treee89b47820d2a3b5a1edd4bbd24fa795addebaa18 /csci1913/Java
parentLeave this shit be (diff)
downloadhomework-3a19175f16f28eea198a85d3e25eee672832b7ea.tar
homework-3a19175f16f28eea198a85d3e25eee672832b7ea.tar.gz
homework-3a19175f16f28eea198a85d3e25eee672832b7ea.tar.bz2
homework-3a19175f16f28eea198a85d3e25eee672832b7ea.tar.lz
homework-3a19175f16f28eea198a85d3e25eee672832b7ea.tar.xz
homework-3a19175f16f28eea198a85d3e25eee672832b7ea.tar.zst
homework-3a19175f16f28eea198a85d3e25eee672832b7ea.zip
This project is no funno
Diffstat (limited to 'csci1913/Java')
-rw-r--r--csci1913/Java/lab6/lab6/Polygon.java32
-rw-r--r--csci1913/Java/lab6/lab6/lab6_strap012.java19
-rw-r--r--csci1913/Java/lab6/lab6/tests6.java28
-rw-r--r--csci1913/Java/lab6_strap012.java64
-rw-r--r--csci1913/Java/project2_strap012.java39
5 files changed, 82 insertions, 100 deletions
diff --git a/csci1913/Java/lab6/lab6/Polygon.java b/csci1913/Java/lab6/lab6/Polygon.java
deleted file mode 100644
index 7f025fe..0000000
--- a/csci1913/Java/lab6/lab6/Polygon.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package lab6;
-
-class Polygon
-{
- private int[] sideLengths;
-
- public Polygon(int sides, int ... lengths)
- {
- int index = 0;
- sideLengths = new int[sides];
- for (int length: lengths)
- {
- sideLengths[index] = length;
- index += 1;
- }
- }
-
- public int side(int number)
- {
- return sideLengths[number];
- }
-
- public int perimeter()
- {
- int total = 0;
- for (int index = 0; index < sideLengths.length; index += 1)
- {
- total += side(index);
- }
- return total;
- }
-}
diff --git a/csci1913/Java/lab6/lab6/lab6_strap012.java b/csci1913/Java/lab6/lab6/lab6_strap012.java
deleted file mode 100644
index feecbe1..0000000
--- a/csci1913/Java/lab6/lab6/lab6_strap012.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package lab6;
-
-class Rectangle extends Polygon {
- public Rectangle(int l, int w) {
- super(4, l, w, l, w);
- }
- public int area() {
- return this.side(0)*this.side(1);
- }
-}
-
-class Square extends Rectangle {
- public Square(int l) {
- super( l, l);
- }
- // public int area() {
- // return this.side(0)*this.side(1);
- // }
-} \ No newline at end of file
diff --git a/csci1913/Java/lab6/lab6/tests6.java b/csci1913/Java/lab6/lab6/tests6.java
deleted file mode 100644
index fc98648..0000000
--- a/csci1913/Java/lab6/lab6/tests6.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package lab6;
-
-// SHAPES. Public tests for the classes RECTANGLE and SQUARE. Comments show
-// what each test must print, and how many points it is worth.
-
-class Shapes
-{
- public static void main(String[] args)
- {
- Rectangle wreck = new Rectangle(3, 5);
-
- System.out.println(wreck.side(0)); // 3 1 point.
- System.out.println(wreck.side(1)); // 5 1 point.
- System.out.println(wreck.side(2)); // 3 1 point.
- System.out.println(wreck.side(3)); // 5 1 point.
- System.out.println(wreck.area()); // 15 1 point.
- System.out.println(wreck.perimeter()); // 16 1 point.
-
- Square nerd = new Square(7);
-
- System.out.println(nerd.side(0)); // 7 1 point.
- System.out.println(nerd.side(1)); // 7 1 point.
- System.out.println(nerd.side(2)); // 7 1 point.
- System.out.println(nerd.side(3)); // 7 1 point.
- System.out.println(nerd.area()); // 49 1 point.
- System.out.println(nerd.perimeter()); // 28 1 point.
- }
-}
diff --git a/csci1913/Java/lab6_strap012.java b/csci1913/Java/lab6_strap012.java
new file mode 100644
index 0000000..62e364a
--- /dev/null
+++ b/csci1913/Java/lab6_strap012.java
@@ -0,0 +1,64 @@
+class Polygon {
+ private int[] sideLengths;
+
+ public Polygon(int sides, int... lengths) {
+ int index = 0;
+ sideLengths = new int[sides];
+ for (int length : lengths) {
+ sideLengths[index] = length;
+ index += 1;
+ }
+ }
+
+ public int side(int number) {
+ return sideLengths[number];
+ }
+
+ public int perimeter() {
+ int total = 0;
+ for (int index = 0; index < sideLengths.length; index += 1) {
+ total += side(index);
+ }
+ return total;
+ }
+}
+
+class Rectangle extends Polygon {
+ public Rectangle(int l, int w) {
+ super(4, l, w, l, w);
+ }
+ public int area() {
+ return this.side(0)*this.side(1);
+ }
+}
+
+class Square extends Rectangle {
+ public Square(int l) {
+ super( l, l);
+ }
+ // public int area() {
+ // return this.side(0)*this.side(1);
+ // }
+}
+
+class Shapes {
+ public static void main(String[] args) {
+ Rectangle wreck = new Rectangle(3, 5);
+
+ System.out.println(wreck.side(0)); // 3 1 point.
+ System.out.println(wreck.side(1)); // 5 1 point.
+ System.out.println(wreck.side(2)); // 3 1 point.
+ System.out.println(wreck.side(3)); // 5 1 point.
+ System.out.println(wreck.area()); // 15 1 point.
+ System.out.println(wreck.perimeter()); // 16 1 point.
+
+ Square nerd = new Square(7);
+
+ System.out.println(nerd.side(0)); // 7 1 point.
+ System.out.println(nerd.side(1)); // 7 1 point.
+ System.out.println(nerd.side(2)); // 7 1 point.
+ System.out.println(nerd.side(3)); // 7 1 point.
+ System.out.println(nerd.area()); // 49 1 point.
+ System.out.println(nerd.perimeter()); // 28 1 point.
+ }
+} \ No newline at end of file
diff --git a/csci1913/Java/project2_strap012.java b/csci1913/Java/project2_strap012.java
index ee09265..69793f0 100644
--- a/csci1913/Java/project2_strap012.java
+++ b/csci1913/Java/project2_strap012.java
@@ -54,32 +54,29 @@ class Sort {
// NUMBER slots, without making new NODEs.
private static Node sortNodes(Node unsorted) {
- Node left = null, right = null, sorted = null;
if (unsorted==null || unsorted.next==null) {
- //unsorted list is either empty or of length 1
+ //unsorted is either empty or of length 1
return unsorted;
- } else {
- //Halving phase
- int step = 1;
- while (unsorted != null) {
- if (step % 2 == 0) { //Odd case
- if (right == null) {
- right = unsorted;
- } else {
-
- }
- } else { //Even case
- if (left == null) {
- left = unsorted;
- } else {
-
- }
+ } //Halving phase
+ Node left = null, right = null, sorted = null;
+ int step = 1;
+ while (unsorted != null) {
+ if (step % 2 == 0) { //Odd case
+ if (right == null) {
+ right = unsorted;
+ } else {
+ right.next = unsorted;
+ }
+ } else { //Even case
+ if (left == null) {
+ left = unsorted;
+ } else {
+ left.next = unsorted;
}
- step++;
- unsorted = unsorted.next;
}
+ step++;
+ unsorted = unsorted.next;
}
-
return sorted;
}