master
Caleb Fontenot 2023-03-14 10:03:24 +07:00
parent d130aa4525
commit 9e597946c2
7 changed files with 231 additions and 104 deletions

1
.gitignore vendored

@ -112,3 +112,4 @@
/Semester 1/Assignments/test/target/
/Semester 2/Assignments/test/target/
/Semester 2/Assignments/lab5__CalebFontenot/target/
/Semester 2/Assignments/MP4_CalebFontenot/target/

@ -8,12 +8,11 @@ package com.calebfontenot.mp4_calebfontenot;
*
* @author caleb
*/
public abstract class Bicycle {
abstract public class Bicycle
{
private int cadence;
private int gear;
private int speed;
public Bicycle(int cadence, int gear, int speed)
{
this.cadence = cadence;
@ -21,74 +20,18 @@ public abstract class Bicycle {
this.speed = speed;
}
/**
* Get the value of speed
*
* @return the value of speed
*/
public int getSpeed()
{
return speed;
}
/**
* Set the value of speed
*
* @param speed new value of speed
*/
public void setSpeed(int speed)
{
this.speed = speed;
}
/**
* Get the value of gear
*
* @return the value of gear
*/
public int getGear()
{
return gear;
}
/**
* Set the value of gear
*
* @param gear new value of gear
*/
public void setGear(int gear)
{
this.gear = gear;
}
/**
* Get the value of cadence
*
* @return the value of cadence
*/
public int getCadence()
{
return cadence;
}
/**
* Set the value of cadence
*
* @param cadence new value of cadence
*/
public void setCadence(int cadence)
{
this.cadence = cadence;
}
public int getGear(){return gear;}
public void setGear(int gear){this.gear = gear;}
public int getCadence(){return cadence;}
public void setCadence(int cadence){this.cadence = cadence;}
public int getSpeed(){return speed;}
public void setSpeed(int speed){this.speed = speed;}
@Override
public String toString()
{
return "Bicycle{" + "cadence=" + cadence + ", gear=" + gear + ", speed=" + speed + '}';
}
abstract Details calculatedDetails();
abstract Details calculatedDetains();
}

@ -0,0 +1,113 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.calebfontenot.mp4_calebfontenot;
import java.util.ArrayList;
import java.util.Collection;
/**
*
* @author caleb
*/
public class BikeStores
{
ArrayList<ArrayList<Bicycle>> storesOfBikes = new ArrayList<ArrayList<Bicycle>>();
/**Add a bike at storeNumber ( i.e. the storeNumber indicates the store)
*
* @param storeNumber which store
* @param b the bike to add
* @return true if the bike added, false if the storeNumber is invalid or b is null.
*/
public boolean addBike( int storeNumber, Bicycle b)
{
//to be implemented
return false;
}
/** Removes a bike at a specific store.
*
* @param store the store that has the bike
* @param bthe 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 store , Bicycle b)
{
//to be implemented
return false;
}
/**Prints the indexes before each bike , one store per line
*
* @param stores stores of bikes
*/
public static void printAllStores( ArrayList<ArrayList<Bicycle>> stores)
{
for ( int i=0; i < stores.size(); ++i)
for ( int j=0; j < stores.get(i).size(); ++j)
{
}
}
/** Groups bikes by type ans sorts them by the ranking of Details.
* There will be three groups and each group stored in decending order by rank.
* @param stores the stores of bikes
* @return a newly created ArrayList<ArrayList<Bicycle>> with the bikes sorted.
*/
public ArrayList<ArrayList<Bicycle>> sortBikesByType( final ArrayList<ArrayList<Bicycle>> stores)
{
ArrayList<ArrayList<Bicycle>> newStore = new ArrayList<ArrayList<Bicycle>>();
return newStore;
}
/**
* Returns a 2D array containing all the bikes in the store in proper sequence (from first to last element). Store 0 with all its bikes, store 1 with all its bikes, and so on.
* @return a 2D array of all stores with bikes.
*/
public Object[][] toArray() {
//a.toArray();
}
/**
* Retains only the Bicycles in the stores that are contained in the specified collection. In other words, removes from this list all of bikes that are not contained in the specified location.
* @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) {
}
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));
bikes.addBike(0, new SpeedBike(1, 2, 10, 30));
bikes.addBike(0, new MountainBike(1, 2, 3, 20));
bikes.addBike(0, new MountainBike(3, 2, 10, 25));
bikes.addBike(0, new ChildBike(false, 1, 1, 10));
//add 5 bikes to store 1 ( 3 speedbikes, 1 mountain 1 child)
bikes.addBike(1, new SpeedBike(10, 4, 10, 20));
bikes.addBike(1, new SpeedBike(0, 2, 10, 50));
bikes.addBike(1, new SpeedBike(3, 2, 10, 38));
bikes.addBike(1, new MountainBike(1, 3, 5, 44));
bikes.addBike(1, new ChildBike(true, 1, 1, 15));
//add 6 bikes to store 2 ( 2 speedBikes, 2 mountain 2 child )
bikes.addBike(2, new SpeedBike(7, 10, 20, 25));
bikes.addBike(2, new SpeedBike(0, 8, 40, 55));
bikes.addBike(2, new MountainBike(2, 3, 15, 33));
bikes.addBike(2, new MountainBike(1, 3, 15, 24));
bikes.addBike(2, new ChildBike(true, 1, 2, 20));
bikes.addBike(2, new ChildBike(false, 1, 1, 18));
//remove one child bike from store 2
//PRINT
//SORT
//PRINT what the method return
//PRINT the original store
}
}
class NotABike{
}

@ -0,0 +1,44 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.calebfontenot.mp4_calebfontenot;
/**
*
* @author caleb
*/
public class ChildBike extends Bicycle //remove comment in front or extends
{
private boolean helpWheels;
public ChildBike(boolean helpWheels, int cadence, int gear, int speed)
{
super(cadence, gear, speed);
this.helpWheels = helpWheels;
}
public boolean isHelpWheels()
{
return helpWheels;
}
public void setHelpWheels(boolean helpWheels)
{
this.helpWheels = helpWheels;
}
@Override
Details calculatedDetails()
{
return Details.getDetails(this);
}
@Override
public String toString()
{
return super.toString() + "ChildBike{" + "helpWheels=" + helpWheels + '}';
}
}

@ -9,29 +9,49 @@ package com.calebfontenot.mp4_calebfontenot;
* @author caleb
*/
public class Details {
private int rank;
private String info;
public void setRank(int rank)
{
this.rank = rank;
}
public int getRank()
{
return rank;
}
public static Details getDetails(Bicycle b) {
public String getInfo()
{
return info;
}
public static Details getDetails(Bicycle b)
{
Details d = new Details();
if (b instanceof SpeedBike) {
if ((SpeedBike) b.speed) {
if (((SpeedBike) b).getWeight() < 1) {
d.rank = 10;
} else if (((SpeedBike) b).getWeight() > 1 && ((SpeedBike) b).getWeight() < 8) {
d.rank = 9;
} else {
d.rank = 0;
}
} else if (b instanceof MountainBike) {
if (((MountainBike) b).getSeatHeight() > 2) {
d.rank = 10;
} else {
d.rank = 0;
}
} else if (b instanceof ChildBike) {
if (((ChildBike) b).isHelpWheels()) {
d.rank = 10;
} else {
d.rank = 0;
}
} else {
return null;
}
d.info = b.toString();
return d;
}
}

@ -8,30 +8,38 @@ package com.calebfontenot.mp4_calebfontenot;
*
* @author caleb
*/
public class MountainBike extends Bicycle {
public class MountainBike extends Bicycle
{
private int seatHeight;
public MountainBike( int seatHeight, int cadence, int gear, int speed)
public MountainBike(int seatHeight, int cadence, int gear, int speed)
{
super(cadence, gear, speed);
this.seatHeight = seatHeight;
}
public int getSeatHeight()
{
return seatHeight;
}
public void setSeatHeight(int seatHeight)
{
this.seatHeight = seatHeight;
}
@Override
public String toString()
{
return super.toString() + "MountainBike{" + "seatHeight=" + seatHeight + '}';
return super.toString() + " MountainBike{" + "seatHeight=" + seatHeight + '}';
}
/**
* Set the value of seatHeight
*
* @param seatHeight new value of seatHeight
*/
public void setSeatHeight(int seatHeight)
@Override
Details calculatedDetails()
{
this.seatHeight = seatHeight;
return Details.getDetails(this);
}
}

@ -8,7 +8,8 @@ package com.calebfontenot.mp4_calebfontenot;
*
* @author caleb
*/
public class SpeedBike extends Bicycle{
public class SpeedBike extends Bicycle
{
private double weight;
@ -17,22 +18,12 @@ public class SpeedBike extends Bicycle{
super(cadence, gear, speed);
this.weight = weight;
}
/**
* Get the value of weight
*
* @return the value of weight
*/
public double getWeight()
{
return weight;
}
/**
* Set the value of weight
*
* @param weight new value of weight
*/
public void setWeight(double weight)
{
this.weight = weight;
@ -41,7 +32,14 @@ public class SpeedBike extends Bicycle{
@Override
public String toString()
{
return super.toString() + "SpeedBike{" + "weight=" + weight + '}';
return super.toString() + " SpeedBike{" + "weight=" + weight + '}';
}
@Override
Details calculatedDetails()
{
return Details.getDetails(this);
}
}