From d784cb527fab692130dc8f6e7c790a7c2f769db1 Mon Sep 17 00:00:00 2001 From: Caleb Fontenot Date: Thu, 16 Mar 2023 20:58:07 -0500 Subject: [PATCH] MP4 progress --- .../mp4_calebfontenot/Bicycle.java | 5 +- .../mp4_calebfontenot/BikeStores.java | 71 +++++++----------- .../mp4_calebfontenot/ChildBike.java | 1 + .../mp4_calebfontenot/MountainBike.java | 1 + .../mp4_calebfontenot/SpeedBike.java | 1 + Semester 2/ZIPs/MP4_CalebFontenot.zip | Bin 0 -> 9028 bytes 6 files changed, 34 insertions(+), 45 deletions(-) create mode 100644 Semester 2/ZIPs/MP4_CalebFontenot.zip diff --git a/Semester 2/Assignments/MP4_CalebFontenot/src/main/java/com/calebfontenot/mp4_calebfontenot/Bicycle.java b/Semester 2/Assignments/MP4_CalebFontenot/src/main/java/com/calebfontenot/mp4_calebfontenot/Bicycle.java index 4077f33..62355da 100644 --- a/Semester 2/Assignments/MP4_CalebFontenot/src/main/java/com/calebfontenot/mp4_calebfontenot/Bicycle.java +++ b/Semester 2/Assignments/MP4_CalebFontenot/src/main/java/com/calebfontenot/mp4_calebfontenot/Bicycle.java @@ -14,7 +14,7 @@ abstract public class Bicycle private int gear; private int speed; - //@Override + @Override public boolean equals(Object obj) { if (this == obj) { @@ -26,6 +26,7 @@ abstract public class Bicycle if (getClass() != obj.getClass()) { return false; } + final Bicycle other = (Bicycle) obj; if (this.cadence != other.cadence) { return false; @@ -36,8 +37,6 @@ abstract public class Bicycle return this.speed == other.speed; } - - public Bicycle(int cadence, int gear, int speed) { this.cadence = cadence; diff --git a/Semester 2/Assignments/MP4_CalebFontenot/src/main/java/com/calebfontenot/mp4_calebfontenot/BikeStores.java b/Semester 2/Assignments/MP4_CalebFontenot/src/main/java/com/calebfontenot/mp4_calebfontenot/BikeStores.java index 9a42ce7..1ab881f 100644 --- a/Semester 2/Assignments/MP4_CalebFontenot/src/main/java/com/calebfontenot/mp4_calebfontenot/BikeStores.java +++ b/Semester 2/Assignments/MP4_CalebFontenot/src/main/java/com/calebfontenot/mp4_calebfontenot/BikeStores.java @@ -22,15 +22,13 @@ public class BikeStores { * @param b the bike to add * @return true if the bike added, false if the storeNumber is invalid or b is null. */ - public BikeStores() - { + public BikeStores() { for (int i = 0; i < 3; i++) { storesOfBikes.add(new ArrayList()); } } - public boolean addBike(int storeNumber, Bicycle b) - { + public boolean addBike(int storeNumber, Bicycle b) { if (storeNumber < 0 || storeNumber > this.storesOfBikes.size() - 1) { return false; } @@ -55,8 +53,7 @@ public class BikeStores { * @param b the bike to be removed * @return true of the bike is removed, false if the bike does not exist, or bike is null. */ - public boolean removeBike(int storeNumber, Bicycle b) - { + public boolean removeBike(int storeNumber, Bicycle b) { if (storeNumber < 0 || storeNumber > this.storesOfBikes.size() - 1) { return false; } @@ -76,8 +73,7 @@ public class BikeStores { * * @param stores stores of bikes */ - public static void print(ArrayList> stores) - { + public static void print(ArrayList> stores) { for (int i = 0; i < stores.size(); ++i) { System.out.println("---------- " + "printing row " + (i + 1) + " ----------"); for (int j = 0; j < stores.get(i).size(); ++j) { @@ -87,8 +83,7 @@ public class BikeStores { } } - public static void printSingle(ArrayList stores) - { + public static void printSingle(ArrayList stores) { System.out.println("----------" + "printSingle" + "----------"); for (int j = 0; j < stores.size(); ++j) { System.out.println(stores.get(j) + " "); @@ -96,8 +91,7 @@ public class BikeStores { } - public static void printRank(ArrayList stores) - { + public static void printRank(ArrayList stores) { System.out.println("----------" + "printRank" + "----------"); for (int j = 0; j < stores.size(); ++j) { System.out.println(stores.get(j) + " " + stores.get(j).calculatedDetails().getRank()); @@ -111,8 +105,7 @@ public class BikeStores { * @param stores the stores of bikes * @return a newly created ArrayList> with the bikes sorted. */ - public static ArrayList> sortBikesByType(final ArrayList> stores) - { + public static ArrayList> sortBikesByType(final ArrayList> stores) { ArrayList> newStore = new ArrayList>(); // group arrayLists ArrayList mountainBikes = new ArrayList(); @@ -149,8 +142,7 @@ public class BikeStores { return newStore; } - private static void sortType(ArrayList arrList) - { + private static void sortType(ArrayList arrList) { for (int x = 0; x < arrList.size(); ++x) { for (int i = 0; i < arrList.size(); ++i) { for (int j = i + 1; j < arrList.size(); ++j) { @@ -166,15 +158,13 @@ public class BikeStores { } } - public static void print(Object[] arr) - { + public static void print(Object[] arr) { for (Object o : arr) { System.out.println(o); } } - public static void print(Object[][] arr) - { + public static void print(Object[][] arr) { for (int i = 0; i < arr.length; i++) { System.out.println("---------- " + "printing row " + (i + 1) + " ----------"); print(arr[i]); @@ -187,8 +177,7 @@ public class BikeStores { * * @return a 2D array of all stores with bikes. */ - public Object[][] toArray() - { + public Object[][] toArray() { Object[][] arr = new Object[storesOfBikes.size()][]; for (int i = 0; i < storesOfBikes.size(); i++) { arr[i] = storesOfBikes.toArray(); @@ -202,30 +191,25 @@ public class BikeStores { * @param c the bikes to be removed * @return true if any store changed as a result of the call. */ - public boolean retainAll(Collection c) - { - /* - for (int i = 0; i < storesOfBikes.size(); ++i) { - for (int j = 0; j < storesOfBikes.get(i).size(); ++j) { - //for (int x = 0; x < c.size(); ++x) { - Bicycle compare1 = storesOfBikes.get(i).get(j); - //Bicycle compare2 = ((ArrayList) c).get(x); - //if (!compare1.equals(compare2)) { - if (!storesOfBikes.get(i).contains(c)) { - storesOfBikes.get(i).remove(j); - System.out.println("Removing " + compare1); - //} - } + public boolean retainAll(Collection c) { + boolean modified = false; + for (int i = storesOfBikes.size() - 1; i >= 0; i--) { + ArrayList bikes = storesOfBikes.get(i); + for (int j = bikes.size() - 1; j >= 0; j--) { + Bicycle bike = bikes.get(j); + if (!c.contains(bike)) { + bikes.remove(j); + System.out.println("Removing " + bike); + modified = true; + } } } -*/ System.out.println("Bikes to remove:"); printSingle((ArrayList) c); - return true; + return modified; } - public static void main(String[] args) - { + public static void main(String[] args) { BikeStores bikes = new BikeStores(); //add 5 bikes to store 0 ( 2 speedBikes, 2 mountain 1 child) bikes.addBike(0, new SpeedBike(4, 3, 10, 40)); @@ -264,8 +248,11 @@ public class BikeStores { c1.add(new SpeedBike(0, 8, 40, 55)); c1.add(new ChildBike(true, 1, 2, 20)); Bicycle b1 = bikes.storesOfBikes.get(2).get(1); - Bicycle b2 = ((ArrayList) c1).get(0); - System.out.println(b1.equals(b2)); + Bicycle b2 = bikes.storesOfBikes.get(2).get(4); + Bicycle b3 = ((ArrayList) c1).get(0); + Bicycle b4 = ((ArrayList) c1).get(1); + + System.out.println(b1.equals(b3) + " " + b2.equals(b4)); bikes.retainAll(c1); print(bikes.storesOfBikes); diff --git a/Semester 2/Assignments/MP4_CalebFontenot/src/main/java/com/calebfontenot/mp4_calebfontenot/ChildBike.java b/Semester 2/Assignments/MP4_CalebFontenot/src/main/java/com/calebfontenot/mp4_calebfontenot/ChildBike.java index 15faa04..5feff03 100644 --- a/Semester 2/Assignments/MP4_CalebFontenot/src/main/java/com/calebfontenot/mp4_calebfontenot/ChildBike.java +++ b/Semester 2/Assignments/MP4_CalebFontenot/src/main/java/com/calebfontenot/mp4_calebfontenot/ChildBike.java @@ -23,6 +23,7 @@ public class ChildBike extends Bicycle //remove comment in front of extends return false; } final ChildBike other = (ChildBike) obj; + System.out.println("Super returns: " + super.equals(obj)); return this.helpWheels == other.helpWheels && super.equals(obj); } diff --git a/Semester 2/Assignments/MP4_CalebFontenot/src/main/java/com/calebfontenot/mp4_calebfontenot/MountainBike.java b/Semester 2/Assignments/MP4_CalebFontenot/src/main/java/com/calebfontenot/mp4_calebfontenot/MountainBike.java index fb3da18..d2d6312 100644 --- a/Semester 2/Assignments/MP4_CalebFontenot/src/main/java/com/calebfontenot/mp4_calebfontenot/MountainBike.java +++ b/Semester 2/Assignments/MP4_CalebFontenot/src/main/java/com/calebfontenot/mp4_calebfontenot/MountainBike.java @@ -26,6 +26,7 @@ public class MountainBike extends Bicycle return false; } final MountainBike other = (MountainBike) obj; + System.out.println("Super returns: " + super.equals(obj)); return this.seatHeight == other.seatHeight && super.equals(obj); } diff --git a/Semester 2/Assignments/MP4_CalebFontenot/src/main/java/com/calebfontenot/mp4_calebfontenot/SpeedBike.java b/Semester 2/Assignments/MP4_CalebFontenot/src/main/java/com/calebfontenot/mp4_calebfontenot/SpeedBike.java index ea9904d..38c5a04 100644 --- a/Semester 2/Assignments/MP4_CalebFontenot/src/main/java/com/calebfontenot/mp4_calebfontenot/SpeedBike.java +++ b/Semester 2/Assignments/MP4_CalebFontenot/src/main/java/com/calebfontenot/mp4_calebfontenot/SpeedBike.java @@ -31,6 +31,7 @@ public class SpeedBike extends Bicycle return false; } final SpeedBike other = (SpeedBike) obj; + System.out.println("Super returns: " + super.equals(obj)); return Double.doubleToLongBits(this.weight) == Double.doubleToLongBits(other.weight) && super.equals(obj); } diff --git a/Semester 2/ZIPs/MP4_CalebFontenot.zip b/Semester 2/ZIPs/MP4_CalebFontenot.zip new file mode 100644 index 0000000000000000000000000000000000000000..848c586f04b1cf28d6e91c291b0c4991d8239688 GIT binary patch literal 9028 zcmcIqWmJ`0w29Y(h#xO1e9wyFsKCB%~YZZVBlwxp2<8 z13X91`0h8ni!m7M$2*_7-ZdZQJLi0mk$^`)g@HkafjO|YRD`*;aIW@JGC(Z>9Ww)6 zVGF2@0o1~VS?20_To`0z@Tbp1bsyAw$?f}5DO@igSnXtxB)u&7_0Ux zgEyD^Ak{ts|Ab1?bV%eU1qxL_X;-uD#`Mr{4Aav#~~! z=Fig_1w9{P7yxVzO;D$Ir-uguXO6bEV+8{Hl|a$A4+Hhb8$N_pg3^p94B$@-lgrKb zZ08Xu)!+)T^kZOx=H$HalWZEeOOZjN#M*}s)x_&D^eK+{cY|e|cr-t4;YNI4S(M8y z^hWpfx!b^xW_bujGdA~X7aM`&X$<2`VF}U{eBeT*O~)H6mqca-Crn2o!ncOs&#>p` zo!C3@Y)0kbML+ELd8DFmWLx`vDxQ0RV|P2J8GU@ZZOCJHWQ0|cRBTE@9#g0pJbEqR zr8!czAqzGjrA5tWU5k()$QPsfxO#T+dIl6O6_&eaHSuAv*FmI+tGw(E;@RGi$H7W} zHwyTnJocpVdq-(YpD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