Prev | Current Page 502 | Next

Carl Reynolds and Paul Tymann

"Schaum's Outline of Principles of Computer Science"

out.println( "There are " + vehicleCount +
" vehicles." );
System.out.println( "Make of v1 (Ford): " + v1.getMake() );
System.out.println( "Model of v2 (328i): " +
v2.getModel() );
System.out.println( "Color of v3 (gold): " +
v3.getColor() );
System.out.println( "Max occupants of v1 (2): " +
v1.getMaxOccupants() );
double accel = v1.changeSpeed( 70. );
System.out.println( v1.getModel() + " accelerated by " +
accel + "mph to " +
v1.getSpeed() + "mph." );
v1.setMake( "Chevrolet" );
v1.setModel( "Malibu" );
v1.setColor( "white" );
v1.setSpeed( 60. );
System.out.println( "v1 is now a " + v1.getColor() + " "
+ v1.getMake() + " " + v1.getModel() +
" going " + v1.getSpeed() + "mph." );
}
}
5.7 Write a Skateboard class that inherits from Vehicle. Override the changeSpeed method for the
Skateboard class, so that instances of the Skateboard class can never exceed 10mph. If a larger
value is supplied, the method will simply set the speed of the Skateboard to 10.
class Skateboard extends Vehicle {
public Skateboard( String mk, String mdl, String clr ) {
super( mk, mdl, 1, clr );
}
194 ANSWERS TO REVIEW QUESTIONS
public double changeSpeed( double newSpeed ) {
if( newSpeed > 10. ) { newSpeed = 10.


Pages:
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
impregnacja posadzek kamiennych Noclegi nad morzem naprawa komputerów Warszawa spa nad morzem alveo