Lab 5 %u2013 Abstract classes and Inheritance Instructions: Write an abstract su
ID: 3537491 • Letter: L
Question
Lab 5 %u2013 Abstract classes and Inheritance
Instructions:
Write an abstract superclass encapsulating a vehicle: A vehicle has attributes: its owner%u2019s name and its number of wheels. This class has two non-abstract subclasses: one encapsulating a bicycle, and the other encapsulating a motorized vehicle. A motorized vehicle has the following additional attributes: its engine value displacement, in liters; and a method computing and returning a measure of horse-power-the number of liters times the number of wheels.
Deliverables:
1. Write the classes and test them with the supplied client code
2. Explain why the line %u201C// Vehicle v = new Vehicle( "John", 4 ); %u201C would generate a compiler error.
The client (driver) class to test these classes is given below:
public class VehicleClient
{
public static void main( String [] args )
{
// Line below would generate a compiler error
// Vehicle v = new Vehicle( "John", 4 );
MotorizedVehicle mv1 = new MotorizedVehicle( "Mike", 4, 3.2 );
MotorizedVehicle mv2 = new MotorizedVehicle( "Sarah", 4, 4.0 );
System.out.println( mv1 + " has " + mv1.horsePower( ) + " horsepower " );
mv2.setOwner( mv1.getOwner( ) );
if ( mv1.equals( mv2 ) )
System.out.println( "mv1 and mv2 are equal" );
else
System.out.println( "mv1 and mv2 are not equal" );
mv2.setVolumeDisplacement( mv1.getVolumeDisplacement( ) );
if ( mv1.equals( mv2 ) )
System.out.println( "mv1 and mv2 are now equal" );
else
System.out.println( "mv1 and mv2 are still not equal" );
Bicycle b2 = new Bicycle( "Jane", 2 );
System.out.println( " b2 is " + b2 );
}
}
Explanation / Answer
check the link http://ideone.com/6p7vgU
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.