Prev | Current Page 504 | Next

Carl Reynolds and Paul Tymann

"Schaum's Outline of Principles of Computer Science"

driver = driver;
}
public static void main( String[] args ) {
// A main method for testing use only
Bus firstBus = new Bus( "Joe" );
Bus secondBus = new Bus( "Mercedes", "B302", 60,
"Black", "Mary" );
System.out.println( "First bus: " + firstBus.getMake() +
" driven by " + firstBus.getDriver() );
System.out.println( "Second bus: " + secondBus.getMake() +
" driven by " + secondBus.getDriver() );
secondBus.setDriver( "David" );
System.out.println( "Second bus: " + secondBus.getMake() +
" driven by " + secondBus.getDriver() );
}
}
ANSWERS TO REVIEW QUESTIONS 195
5.9 To the class Vehicle, add a refuel method that expects two parameters, fuelQuantity and
milesSince LastFueling. Also add instance variables to the Vehicle class for
totalMileage and totalFuelConsumed. Further, add an accessor method called
fuelEconomy that will return the total miles per gallon of the vehicle.
private double totalFuel = 0.;
private double totalMiles = 0.;
.
.
public void reFuel( double fuelQuantity,
double milesSinceLastFueling ){
totalMiles += milesSinceLastFueling;
totalFuel += fuelQuantity;
}
public double fuelEconomy() {
return totalMiles / totalFuel;
}
What will you do to make the refuel method work properly when invoked on an instance of Skateboard?
class Skateboard extends Vehicle {
public Skateboard( String mk, String mdl, String clr ) {
super( mk, mdl, 1, clr );
}
public double changeSpeed( double newSpeed ) {
if( newSpeed > 10.


Pages:
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516
zasady pokera Wisła noclegi Wiadomosci firmowe reklama internetowa drzwi aluminiowe