Question
Edit question ASAP In Java programming QUESTION 5 A bicycle has two wheels, a number of gears and a body. For this question, you will
Edit question
ASAP In Java programming
QUESTION 5
A bicycle has two wheels, a number of gears and a body. For this question, you will use Java to create and use a bicycle class as follows:
1- Create a class called Wheel. This class has two private instance variables called width and radius, both of type double.
For the Wheel class do the following:
a) Write two constructors for the Wheel class as follows:
- A default constructor that sets the class instance variables to zero
- A constructor that receives two double values as parameters and uses them to set the values of the instance variables.
b) Write the set and get methods for the Wheel class to set and return the values of the instance variables. c) Write a copy constructor for the Wheel class. d) Write an equals() method that compares two wheels. Two wheels are equal if the radius and width of both wheels are the same.
e) Write a toString() method for the Wheel class that prints the class name (Wheel) and the values of its instance variables. 2- Create a class called Bicycle with the following instance variables:
1: wheelOne of type Wheel,
2: wheelTwo of type Wheel, 3: bodyColor of type String, 4:numberOfGears of type integer,
For the Bicycle class do the following: a) Write a constructor that receives values for the instance variables as parameters and sets them. Do not define a default constructor for this class.
Note: Please use the Wheel class copy constructor where necessary
b) Write the set and get methods for the Bicycle class to set and return the values of its instance variables. Please note that:
- The set methods that assign values to the wheelOne and wheelTwo, should receive Wheel objects as parameters.
- The wheelOne and wheelTwo get methods will return Wheel objects.
- Use the Wheel class copy constructor where necessary
c) Write a toString() method for the Bicycle class that prints the class name (Bicycle) and the value of its instance variables. 3- Test the above classes by writing a class called BicycleTest.java that does the following: a) Creates an instance of Bicycle as follows:
- wheelOne: width = 0.9, radius = 26.0 (This Wheel object needs to be created) - wheelTwo: width = 1.0, radius = 27.0 (This Wheel object needs to be created) - bodyColor: "Red" - numberOfGears: 21
b) Prints the Bicycle object. c) Changes the numberOfGears to 24. d) Prints the Bicycle object again. e) Compares wheelOne and wheelTwo to see if they are equal and prints "Equal" or "Not Equal", accordingly.
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