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 0000000..848c586 Binary files /dev/null and b/Semester 2/ZIPs/MP4_CalebFontenot.zip differ