Write a new class named RoadBike that extends the Bicycle class Add a simple con
ID: 3603162 • Letter: W
Question
Write a new class named RoadBike that extends the Bicycle class
Add a simple constructor to MyBike that initializes the RoadBike class to MyRide2.
Set the speed for MyRide2 to 24.6
Print the message "My Road Bikes speed is: X" where X is the speed of the MyRide2
I am providing you the code for the bicycle class
package bicycle;
public class Bicycle {
// the Bicycle class has three fields
private int cadence = 25;
private int gear;
private double speed;
// the Bicycle class has six methods
public void setCadence(int newValue) {
cadence = newValue;
}
public void setGear(int newValue) {
gear = newValue;
}
public void setSpeed(double newValue) {
speed = newValue;
}
public void applyBrake(double decrement) {
//mod to return new speed
speed -= decrement;
}
public void speedUp(double increment) {
// mod to return new speed
speed += increment;
}
public double getSpeed() {
return speed;
}
public double getRatio() {
return cadence / gear;
}
}
code for mountain bike
package bicycle;
public class MountainBike extends Bicycle {
// the MountainBike subclass has one field
private double bikeCost = 1000;
// the MountainBike subclass has two methods
public void setCost(double newValue) {
bikeCost = newValue;
}
public double getCost() {
return bikeCost;
}
}
code for mybike class
package bicycle;
public class MyBike {
// the MyBike subclass has one static field
public static String BIKETYPE = "TREK";
// the MyBike subclass has one method
public static void main(String[] args) {
// the MountainBike subclass has one no-argument constructor
MountainBike myRide = new MountainBike();
myRide.setGear( 3 );
myRide.setSpeed( 18.7 );
// myRide.getCost();
// variable is private and hidden
// System.out.println( "My " + BIKETYPE + "'s speed is: " + myRide.speed );
System.out.println( "My " + BIKETYPE + "'s ratio is: " + myRide.getRatio() );
System.out.println( "My " + BIKETYPE + "'s speed is: " + myRide.getSpeed() );
myRide.speedUp( 1.1 );
System.out.println( "My " + BIKETYPE + "'s speed is: " + myRide.getSpeed() );
System.out.println( "My " + BIKETYPE + "'s cost is: " + myRide.getCost() );
myRide.setCost( 777.77 );
System.out.println( "My " + BIKETYPE + "'s cost is: " + myRide.getCost() );
// System.out.println( "My " + BIKETYPE + "'s cadence is: " + cadence;
}
}
please reply me the code in java using a eclipse. I want the answer as per the code which i provided.
Thankyou
Explanation / Answer
public class Bicycle {
// the Bicycle class has three fields
private int cadence = 25;
private int gear;
private double speed;
// the Bicycle class has six methods
public void setCadence(int newValue) {
cadence = newValue;
}
public void setGear(int newValue) {
gear = newValue;
}
public void setSpeed(double newValue) {
speed = newValue;
}
public void applyBrake(double decrement) {
//mod to return new speed
speed -= decrement;
}
public void speedUp(double increment) {
// mod to return new speed
speed += increment;
}
public double getSpeed() {
return speed;
}
public double getRatio() {
return cadence / gear;
}
}
code for mountain bike
package bicycle;
public class MountainBike extends Bicycle {
// the MountainBike subclass has one field
private double bikeCost = 1000;
// the MountainBike subclass has two methods
public void setCost(double newValue) {
bikeCost = newValue;
}
public double getCost() {
return bikeCost;
}
}
code for mybike class
public class MyBike {
// the MyBike subclass has one static field
public static String BIKETYPE = "TREK";
// the MyBike subclass has one method
public static void main(String[] args) {
// the MountainBike subclass has one no-argument constructor
MountainBike myRide = new MountainBike();
myRide.setGear( 3 );
myRide.setSpeed( 18.7 );
// myRide.getCost();
// variable is private and hidden
// System.out.println( "My " + BIKETYPE + "'s speed is: " + myRide.speed );
System.out.println( "My " + BIKETYPE + "'s ratio is: " + myRide.getRatio() );
System.out.println( "My " + BIKETYPE + "'s speed is: " + myRide.getSpeed() );
myRide.speedUp( 1.1 );
System.out.println( "My " + BIKETYPE + "'s speed is: " + myRide.getSpeed() );
System.out.println( "My " + BIKETYPE + "'s cost is: " + myRide.getCost() );
myRide.setCost( 777.77 );
System.out.println( "My " + BIKETYPE + "'s cost is: " + myRide.getCost() );
// System.out.println( "My " + BIKETYPE + "'s cadence is: " + cadence;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.