) { newSpeed = 10.; }
double accel = newSpeed - this.getSpeed();
this.setSpeed( newSpeed );
return accel;
}
public double fuelEconomy()
throws UnsupportedOperationException {
throw new UnsupportedOperationException(
"Skateboard uses no fuel" );
}
public void reFuel(double gallons, double miles)
throws UnsupportedOperationException {
throw new UnsupportedOperationException(
"Skateboard uses no fuel" );
}
}
Write a test class called ManyVehicles that creates a variety of different Vehicles, exercises all the
methods you have created, and checks for proper execution. Try to set the speed of a Skateboard to
60, for example, or to refuel a Skateboard. Check that the fuel economy calculations are being
performed correctly.
public class ManyVehicles {
// main method: tests the Vehicle class
public static void main( String[] args ) {
Vehicle v1, v2, v3, v4;
196 ANSWERS TO REVIEW QUESTIONS
v1 = new Vehicle( "Ford", "Mustang", 2, "red" );
v2 = new Vehicle( "BMW", "328i", 4, "silver" );
v3 = new Vehicle( "Chrysler", "PT Cruiser", 4, "gold" );
System.out.println( "There are " + Vehicle.vehicleCount
+ " vehicles." );
System.out.println( "Make of v1 (Ford): " + v1.getMake() );
System.out.println( "Model of v2 (328i):" +
v2.
Pages:
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517