Answered step by step
Verified Expert Solution
Question
1 Approved Answer
/ / instance variable declarations private int gears = 0 ; private double cost = 0 . 0 ; private double weight = 0 .
instance variable declarations private int gears ; private double cost ; private double weight ; private String color ; constructor default public Bicycle constructor String parameter public BicycleString aColor this.color aColor; constructor int parameter public Bicycleint nbrOfGears this.gears nbrOfGears; constructor int, double, double, String parameters public Bicycleint nbrOfGears, double theCost, double theWeight, String aColor this.gears nbrOfGears; this.cost theCost; this.weight theWeight; this.color aColor; method to output Bicycle's information public void outputData System.out.println Bicycle Details:"; System.out.printlnGears : this.gears; System.out.printlnCost : this.cost; System.out.printlnWeight : this.weight lbs; System.out.printlnColor : this.color; method to output Bicycle's information overloaded method call chaining enabled public Bicycle outputDataString bikeText System.out.println Bicycle bikeText Details:"; System.out.printlnGears : this.gears; System.out.printlnCost : this.cost; System.out.printlnWeight : this.weight lbs; System.out.printlnColor : this.color; return this; Accessors Getters public int getGears return this.gears; public double getCost return this.cost; public double getWeight return this.weight; public String getColor return this.color; Mutators Setters method call chaining enabled public Bicycle setGearsint nbr this.gears nbr; return this; public Bicycle setCostdouble amt this.cost amt; return this; public Bicycle setWeightdouble lbs this.weight lbs; return this; public Bicycle setColorString theColor this.color theColor; return this; package com.three; public class Driver public static void mainString args Example calls to mutators Bicycle myBike new Bicycle; myBike.setGears; myBike.setCost; myBike.setWeight; myBike.setColorPurple; System.out.println myBike's color is myBike.getColor; Example of calls to overloaded constructor Bicycle myBike new Bicycle; Bicycle myBike new BicycleBrown; Bicycle myBike new Bicycle; Bicycle myBike new Bicycle "White"; myBikeoutputDataNbr ; myBikeoutputDataNbr ; myBikeoutputDataNbr ; myBikeoutputDataNbr ; Example using method call chaining Bicycle myBike new Bicycle "Green"; myBikesetColorPeachsetGearsoutputDataNumber ; IS A Checks System.out.println IS A CHECKS"; focus on myBike Bicycle myBike new Bicycle; if myBike instanceof Bicycle System.out.printlnmyBike Instance of Bicycle: True"; else System.out.printlnmyBike Instance of Bicycle: False"; if myBike instanceof TwoWheeled System.out.printlnmyBike Instance of TwoWheeled: True"; else System.out.printlnmyBike Instance of TwoWheeled: False"; if myBike instanceof Vehicle System.out.printlnmyBike Instance of Vehicle: True"; else System.out.printlnmyBike Instance of Vehicle: False"; if myBike instanceof Object System.out.printlnmyBike Instance of Object: True"; else System.out.printlnmyBike Instance of Object: False"; focus on TwoWheeled TwoWheeled myTwoWheeled new TwoWheeled; if myTwoWheeled instanceof Bicycle System.out.println myTwoWheeled Instance of Bicycle: True"; else System.out.println myTwoWheeled Instance of Bicycle: False"; if myTwoWheeled instanceof TwoWheeled System.out.printlnmyTwoWheeled Instance of TwoWheeled: True"; else System.out.printlnmyTwoWheeled Instance of TwoWheeled: False"; if myTwoWheeled instanceof Vehicle System.out.printlnmyTwoWheeled Instance of Vehicle: True"; else System.out.print
instance variable declarations
private int gears ;
private double cost ;
private double weight ;
private String color ;
constructor default
public Bicycle
constructor String parameter
public BicycleString aColor
this.color aColor;
constructor int parameter
public Bicycleint nbrOfGears
this.gears nbrOfGears;
constructor int, double, double, String parameters
public Bicycleint nbrOfGears, double theCost, double theWeight, String aColor
this.gears nbrOfGears;
this.cost theCost;
this.weight theWeight;
this.color aColor;
method to output Bicycle's information
public void outputData
System.out.println
Bicycle Details:";
System.out.printlnGears : this.gears;
System.out.printlnCost : this.cost;
System.out.printlnWeight : this.weight lbs;
System.out.printlnColor : this.color;
method to output Bicycle's information overloaded
method call chaining enabled
public Bicycle outputDataString bikeText
System.out.println
Bicycle bikeText Details:";
System.out.printlnGears : this.gears;
System.out.printlnCost : this.cost;
System.out.printlnWeight : this.weight lbs;
System.out.printlnColor : this.color;
return this;
Accessors Getters
public int getGears
return this.gears;
public double getCost
return this.cost;
public double getWeight
return this.weight;
public String getColor
return this.color;
Mutators Setters method call chaining enabled
public Bicycle setGearsint nbr
this.gears nbr;
return this;
public Bicycle setCostdouble amt
this.cost amt;
return this;
public Bicycle setWeightdouble lbs
this.weight lbs;
return this;
public Bicycle setColorString theColor
this.color theColor;
return this;
package com.three;
public class Driver
public static void mainString args
Example calls to mutators
Bicycle myBike new Bicycle;
myBike.setGears;
myBike.setCost;
myBike.setWeight;
myBike.setColorPurple;
System.out.println
myBike's color is myBike.getColor;
Example of calls to overloaded constructor
Bicycle myBike new Bicycle;
Bicycle myBike new BicycleBrown;
Bicycle myBike new Bicycle;
Bicycle myBike new Bicycle "White";
myBikeoutputDataNbr ;
myBikeoutputDataNbr ;
myBikeoutputDataNbr ;
myBikeoutputDataNbr ;
Example using method call chaining
Bicycle myBike new Bicycle "Green";
myBikesetColorPeachsetGearsoutputDataNumber ;
IS A Checks
System.out.println
IS A CHECKS";
focus on myBike
Bicycle myBike new Bicycle;
if myBike instanceof Bicycle
System.out.printlnmyBike Instance of Bicycle: True";
else
System.out.printlnmyBike Instance of Bicycle: False";
if myBike instanceof TwoWheeled
System.out.printlnmyBike Instance of TwoWheeled: True";
else
System.out.printlnmyBike Instance of TwoWheeled: False";
if myBike instanceof Vehicle
System.out.printlnmyBike Instance of Vehicle: True";
else
System.out.printlnmyBike Instance of Vehicle: False";
if myBike instanceof Object
System.out.printlnmyBike Instance of Object: True";
else
System.out.printlnmyBike Instance of Object: False";
focus on TwoWheeled
TwoWheeled myTwoWheeled new TwoWheeled;
if myTwoWheeled instanceof Bicycle
System.out.println
myTwoWheeled Instance of Bicycle: True";
else
System.out.println
myTwoWheeled Instance of Bicycle: False";
if myTwoWheeled instanceof TwoWheeled
System.out.printlnmyTwoWheeled Instance of TwoWheeled: True";
else
System.out.printlnmyTwoWheeled Instance of TwoWheeled: False";
if myTwoWheeled instanceof Vehicle
System.out.printlnmyTwoWheeled Instance of Vehicle: True";
else
System.out.print
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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