MP4 progress
This commit is contained in:
parent
e2aa4c2894
commit
d784cb527f
@ -14,7 +14,7 @@ abstract public class Bicycle
|
|||||||
private int gear;
|
private int gear;
|
||||||
private int speed;
|
private int speed;
|
||||||
|
|
||||||
//@Override
|
@Override
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj)
|
||||||
{
|
{
|
||||||
if (this == obj) {
|
if (this == obj) {
|
||||||
@ -26,6 +26,7 @@ abstract public class Bicycle
|
|||||||
if (getClass() != obj.getClass()) {
|
if (getClass() != obj.getClass()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Bicycle other = (Bicycle) obj;
|
final Bicycle other = (Bicycle) obj;
|
||||||
if (this.cadence != other.cadence) {
|
if (this.cadence != other.cadence) {
|
||||||
return false;
|
return false;
|
||||||
@ -36,8 +37,6 @@ abstract public class Bicycle
|
|||||||
return this.speed == other.speed;
|
return this.speed == other.speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public Bicycle(int cadence, int gear, int speed)
|
public Bicycle(int cadence, int gear, int speed)
|
||||||
{
|
{
|
||||||
this.cadence = cadence;
|
this.cadence = cadence;
|
||||||
|
@ -22,15 +22,13 @@ public class BikeStores {
|
|||||||
* @param b the bike to add
|
* @param b the bike to add
|
||||||
* @return true if the bike added, false if the storeNumber is invalid or b is null.
|
* @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++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
storesOfBikes.add(new ArrayList<Bicycle>());
|
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) {
|
if (storeNumber < 0 || storeNumber > this.storesOfBikes.size() - 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -55,8 +53,7 @@ public class BikeStores {
|
|||||||
* @param b the bike to be removed
|
* @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.
|
* @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) {
|
if (storeNumber < 0 || storeNumber > this.storesOfBikes.size() - 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -76,8 +73,7 @@ public class BikeStores {
|
|||||||
*
|
*
|
||||||
* @param stores stores of bikes
|
* @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) {
|
for (int i = 0; i < stores.size(); ++i) {
|
||||||
System.out.println("---------- " + "printing row " + (i + 1) + " ----------");
|
System.out.println("---------- " + "printing row " + (i + 1) + " ----------");
|
||||||
for (int j = 0; j < stores.get(i).size(); ++j) {
|
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" + "----------");
|
System.out.println("----------" + "printSingle" + "----------");
|
||||||
for (int j = 0; j < stores.size(); ++j) {
|
for (int j = 0; j < stores.size(); ++j) {
|
||||||
System.out.println(stores.get(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" + "----------");
|
System.out.println("----------" + "printRank" + "----------");
|
||||||
for (int j = 0; j < stores.size(); ++j) {
|
for (int j = 0; j < stores.size(); ++j) {
|
||||||
System.out.println(stores.get(j) + " " + stores.get(j).calculatedDetails().getRank());
|
System.out.println(stores.get(j) + " " + stores.get(j).calculatedDetails().getRank());
|
||||||
@ -111,8 +105,7 @@ public class BikeStores {
|
|||||||
* @param stores the stores of bikes
|
* @param stores the stores of bikes
|
||||||
* @return a newly created ArrayList<ArrayList<Bicycle>> with the bikes sorted.
|
* @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>>();
|
ArrayList<ArrayList<Bicycle>> newStore = new ArrayList<ArrayList<Bicycle>>();
|
||||||
// group arrayLists
|
// group arrayLists
|
||||||
ArrayList<Bicycle> mountainBikes = new ArrayList<Bicycle>();
|
ArrayList<Bicycle> mountainBikes = new ArrayList<Bicycle>();
|
||||||
@ -149,8 +142,7 @@ public class BikeStores {
|
|||||||
return newStore;
|
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 x = 0; x < arrList.size(); ++x) {
|
||||||
for (int i = 0; i < arrList.size(); ++i) {
|
for (int i = 0; i < arrList.size(); ++i) {
|
||||||
for (int j = i + 1; j < arrList.size(); ++j) {
|
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) {
|
for (Object o : arr) {
|
||||||
System.out.println(o);
|
System.out.println(o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void print(Object[][] arr)
|
public static void print(Object[][] arr) {
|
||||||
{
|
|
||||||
for (int i = 0; i < arr.length; i++) {
|
for (int i = 0; i < arr.length; i++) {
|
||||||
System.out.println("---------- " + "printing row " + (i + 1) + " ----------");
|
System.out.println("---------- " + "printing row " + (i + 1) + " ----------");
|
||||||
print(arr[i]);
|
print(arr[i]);
|
||||||
@ -187,8 +177,7 @@ public class BikeStores {
|
|||||||
*
|
*
|
||||||
* @return a 2D array of all stores with bikes.
|
* @return a 2D array of all stores with bikes.
|
||||||
*/
|
*/
|
||||||
public Object[][] toArray()
|
public Object[][] toArray() {
|
||||||
{
|
|
||||||
Object[][] arr = new Object[storesOfBikes.size()][];
|
Object[][] arr = new Object[storesOfBikes.size()][];
|
||||||
for (int i = 0; i < storesOfBikes.size(); i++) {
|
for (int i = 0; i < storesOfBikes.size(); i++) {
|
||||||
arr[i] = storesOfBikes.toArray();
|
arr[i] = storesOfBikes.toArray();
|
||||||
@ -202,30 +191,25 @@ public class BikeStores {
|
|||||||
* @param c the bikes to be removed
|
* @param c the bikes to be removed
|
||||||
* @return true if any store changed as a result of the call.
|
* @return true if any store changed as a result of the call.
|
||||||
*/
|
*/
|
||||||
public boolean retainAll(Collection<Bicycle> c)
|
public boolean retainAll(Collection<Bicycle> c) {
|
||||||
{
|
boolean modified = false;
|
||||||
/*
|
for (int i = storesOfBikes.size() - 1; i >= 0; i--) {
|
||||||
for (int i = 0; i < storesOfBikes.size(); ++i) {
|
ArrayList<Bicycle> bikes = storesOfBikes.get(i);
|
||||||
for (int j = 0; j < storesOfBikes.get(i).size(); ++j) {
|
for (int j = bikes.size() - 1; j >= 0; j--) {
|
||||||
//for (int x = 0; x < c.size(); ++x) {
|
Bicycle bike = bikes.get(j);
|
||||||
Bicycle compare1 = storesOfBikes.get(i).get(j);
|
if (!c.contains(bike)) {
|
||||||
//Bicycle compare2 = ((ArrayList<Bicycle>) c).get(x);
|
bikes.remove(j);
|
||||||
//if (!compare1.equals(compare2)) {
|
System.out.println("Removing " + bike);
|
||||||
if (!storesOfBikes.get(i).contains(c)) {
|
modified = true;
|
||||||
storesOfBikes.get(i).remove(j);
|
|
||||||
System.out.println("Removing " + compare1);
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
System.out.println("Bikes to remove:");
|
System.out.println("Bikes to remove:");
|
||||||
printSingle((ArrayList<Bicycle>) c);
|
printSingle((ArrayList<Bicycle>) c);
|
||||||
return true;
|
return modified;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args)
|
public static void main(String[] args) {
|
||||||
{
|
|
||||||
BikeStores bikes = new BikeStores();
|
BikeStores bikes = new BikeStores();
|
||||||
//add 5 bikes to store 0 ( 2 speedBikes, 2 mountain 1 child)
|
//add 5 bikes to store 0 ( 2 speedBikes, 2 mountain 1 child)
|
||||||
bikes.addBike(0, new SpeedBike(4, 3, 10, 40));
|
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 SpeedBike(0, 8, 40, 55));
|
||||||
c1.add(new ChildBike(true, 1, 2, 20));
|
c1.add(new ChildBike(true, 1, 2, 20));
|
||||||
Bicycle b1 = bikes.storesOfBikes.get(2).get(1);
|
Bicycle b1 = bikes.storesOfBikes.get(2).get(1);
|
||||||
Bicycle b2 = ((ArrayList<Bicycle>) c1).get(0);
|
Bicycle b2 = bikes.storesOfBikes.get(2).get(4);
|
||||||
System.out.println(b1.equals(b2));
|
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);
|
bikes.retainAll(c1);
|
||||||
print(bikes.storesOfBikes);
|
print(bikes.storesOfBikes);
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ public class ChildBike extends Bicycle //remove comment in front of extends
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final ChildBike other = (ChildBike) obj;
|
final ChildBike other = (ChildBike) obj;
|
||||||
|
System.out.println("Super returns: " + super.equals(obj));
|
||||||
return this.helpWheels == other.helpWheels && super.equals(obj);
|
return this.helpWheels == other.helpWheels && super.equals(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ public class MountainBike extends Bicycle
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final MountainBike other = (MountainBike) obj;
|
final MountainBike other = (MountainBike) obj;
|
||||||
|
System.out.println("Super returns: " + super.equals(obj));
|
||||||
return this.seatHeight == other.seatHeight && super.equals(obj);
|
return this.seatHeight == other.seatHeight && super.equals(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ public class SpeedBike extends Bicycle
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final SpeedBike other = (SpeedBike) obj;
|
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);
|
return Double.doubleToLongBits(this.weight) == Double.doubleToLongBits(other.weight) && super.equals(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIN
Semester 2/ZIPs/MP4_CalebFontenot.zip
Normal file
BIN
Semester 2/ZIPs/MP4_CalebFontenot.zip
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user