MP4 progress

This commit is contained in:
Chloe Fontenot 🏳️‍⚧️ 2023-03-16 20:58:07 -05:00
parent e2aa4c2894
commit d784cb527f
6 changed files with 34 additions and 45 deletions

View File

@ -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;

View File

@ -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<Bicycle>());
}
}
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<ArrayList<Bicycle>> stores)
{
public static void print(ArrayList<ArrayList<Bicycle>> 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<Bicycle> stores)
{
public static void printSingle(ArrayList<Bicycle> 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<Bicycle> stores)
{
public static void printRank(ArrayList<Bicycle> 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<ArrayList<Bicycle>> with the bikes sorted.
*/
public static ArrayList<ArrayList<Bicycle>> sortBikesByType(final ArrayList<ArrayList<Bicycle>> stores)
{
public static ArrayList<ArrayList<Bicycle>> sortBikesByType(final ArrayList<ArrayList<Bicycle>> stores) {
ArrayList<ArrayList<Bicycle>> newStore = new ArrayList<ArrayList<Bicycle>>();
// group arrayLists
ArrayList<Bicycle> mountainBikes = new ArrayList<Bicycle>();
@ -149,8 +142,7 @@ public class BikeStores {
return newStore;
}
private static void sortType(ArrayList<Bicycle> arrList)
{
private static void sortType(ArrayList<Bicycle> 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<Bicycle> 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<Bicycle>) 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<Bicycle> c) {
boolean modified = false;
for (int i = storesOfBikes.size() - 1; i >= 0; i--) {
ArrayList<Bicycle> 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<Bicycle>) 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<Bicycle>) c1).get(0);
System.out.println(b1.equals(b2));
Bicycle b2 = bikes.storesOfBikes.get(2).get(4);
Bicycle b3 = ((ArrayList<Bicycle>) c1).get(0);
Bicycle b4 = ((ArrayList<Bicycle>) c1).get(1);
System.out.println(b1.equals(b3) + " " + b2.equals(b4));
bikes.retainAll(c1);
print(bikes.storesOfBikes);

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

Binary file not shown.