This exercise demonstrates using a reference parameter to pass data back to the calling method. Suppose you want a
Car5class to include a method with this heading:
public boolean copyTo(Car5 newCar)
This method is supposed to be called by an existing
Car5object with another
Car5object as the argument. If any of the calling car’s instance variables has not been initialized, the desired method should not try to modify any of the new car’s instance variable values, and the method should return
false.Otherwise, the method should copy all of the calling car’s instance variable values into the new car and return
true.Here’s a driver that illustrates the usage:
/***************************************************************** Car5Driver.java* Dean&Dean** This class is a demonstration driver for the Car5 class.****************************************************************/public class Car5Driver{ public static void main(String[] args) { Car5 silviaCar = new Car5(); Car5 jayCar = new Car5(); System.out.println(silviaCar.copyTo(jayCar)); silviaCar = new Car5("Fiat", 2015, "black"); System.out.println(silviaCar.copyTo(jayCar)); } // end main} // end class Car5DriverOutput:
falsetrue
Write the code for the desired
copyTomethod.
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.