Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Updated the question Perform the following tasks: 1. Install the Bicycle project from this week's code file Run and test Write a new class named
Updated the question
Perform the following tasks:
- 1. Install the Bicycle project from this week's code file
- Run and test
- Write a new class named RoadBike that extends the Bicycle class
- Add a simple constructor to RoadBike 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
-
- 2. Write a new class called ConvertMe
- create an int with the value of the current year
- convert it to a long
- convert it to a short
- create a byte with the value of your age
- convert it to a double
- convert it to an int
- print all the results
- create an int with the value of the current year
- 2. Write a new class called ConvertMe
- Posting the Bicycle project below
-
package bicycle; public class Bicycle { // the Bicycle class has three fields private int cadence = 25; // public 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; } }
-
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; } }
-
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: " + myRide.cadence ); } }
- I am writing code on java eclipse. Thanks
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started