Hello everyone
i came here seeking help on doing some program about bicycles for the university..
and asked
Write a TestBikes Main Class that will declare array of bikes of type Bicycle of size 6. Fill it with 6 objetcs of different types that the user will decide. Allow the user to speed up or slow down the speed of any object of his/her choice. Allow the user to get or set any attribute of any object of his/her choice. The attributes of these objects are entered by the user. Then, print the description of all bikes.
i made all the classes, i just don't know how to make the main method properly, here is my code:
import java.util.*; abstract public class Bicycle { protected int startCadence; protected int startSpeed; protected int startGear; public Bicycle (int startCadence,int startSpeed, int startGear){ this.startCadence = startCadence; this.startSpeed = startSpeed; this.startGear = startGear; } public int getStartCadence() { return startCadence; } public void setStartCadence(int startCadence) { this.startCadence = startCadence; } public int getStartGear() { return startGear; } public void setStartGear(int startGear) { this.startGear = startGear; } public int getStartSpeed() { return startSpeed; } public void setStartSpeed(int startSpeed) { this.startSpeed = startSpeed; } public void applyBrake(int slower){ //will decrement the speed by slower } public void speedUp(int faster){ //) will increment the speed by faster } public void printDescription(){ System.out.println("Bike is in gear this.gear with a caence of this.cadence and travelling at a speed of this.speed"); } }
public class RoadBike extends Bicycle{ private int tireWidth; public RoadBike(int tireWidth, int startCadence, int startSpeed, int startGear) { super(startCadence, startSpeed, startGear); this.tireWidth = tireWidth; } public int getTireWidth() { return tireWidth; } public void setTireWidth(int tireWidth) { this.tireWidth = tireWidth; } public void printDescription(){ } }
public class MountainBike extends RoadBike{ private String suspension; private int seatHeight; public MountainBike(String suspension, int seatHeight, int tireWidth, int startCadence, int startSpeed, int startGear) { super(tireWidth, startCadence, startSpeed, startGear); this.suspension = suspension; this.seatHeight = seatHeight; } public int getHeight() { return seatHeight; } public void setHeight(int seatHeight) { this.seatHeight = seatHeight; } public String getSuspension() { return suspension; } public void setSuspension(String suspension) { this.suspension = suspension; } public void printDescription(){ } }
main class
package assignment_3; import java.util.Scanner; public class TestBikes { public void main (String [] args){ Scanner scan = new Scanner (System.in); String[]ar = new String [6]; } }
as you see i'm not good at connecting classes and using them in the main class
much appreciated any help and thank you