Here is the question the instructor provided us with: I am unsure as to how to make an if statement that will check variables I created in the BikeTester class. The variables I am using were declared as instance variables in the Bike Class. Could anyone please help me solve step 4 in the biketester class?
Bike Class
Create a class called Bike which has only the following instance variables:
Number of wheels
Diameter of tires
Manufacturer name
Year built
Create the no-argument constructor
Create the constructor which uses all fields as parameters
Write the getter and setter methods for all instance variables
Override the toString method using the example shown above
There should be NO main method in the Bike class.
BikeTester Class
Create a class called BikeTester which constructs 10 different Bike objects
Add each Bike object to an array
Use a for loop to SOP each Bike reference
Use a second for loop to SOP only those bikes that are built after 2004 and have a wheel diameter of greater than 4
I am on the last step (step 4 in part 2).
I have the following code:
// four argument constructor from the Bike Class
public Bike(int wheels, double tires, String manuf, int year)
{ numWheels = wheels; diameterOfTires = tires; manufacturer = manuf; yearBuilt = year; }
Bike bike10 = new Bike(5, 2.5, "Bob", 1995);
//excluded the other 9 bike objects to just grasp the idea.
Bike[] bikes = new Bike[10];
bikes[0] = bike1;
bikes[1] = bike2;
bikes[2] = bike3;
bikes[3] = bike4;
bikes[4] = bike5;
bikes[5] = bike6;
bikes[6] = bike7;
bikes[7] = bike8;
bikes[8] = bike9;
bikes[9] = bike10;
//step 4 that i need help on
for (int y = 0; y < bikes.length; y++) //my loop to solve the problem (doesnt work)
{
if(yearBuilt > 2004 && diameterOfTires > 4)
{
System.out.println(bikes[y]);
}
}
Thank you! any help would be nice as I am stuck trying to solve this!