Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Program The Vehicle class and its subclasses ( filename: TestVehicle.java) Define a class named Vehicle that contains the manufacturers name, and the number of

Java Program

The Vehicle class and its subclasses (filename: TestVehicle.java)

  1. Define a class named Vehicle that contains the manufacturers name, and the number of wheels, and appropriate constructors and accessor and mutator methods. Also override the toString() method that returns an English sentence describing the manufacturer's name and the number of wheels.

  1. Next define a class named Truck that extends the Vehicle class. The Truck class has two additional data fields. They are the load capacity in tons (type double) and towing capacity in pounds (type int). Include appropriate constructor(s) and accessors and mutators. This class should override the toString() method to return a string that includes all the information about a Truck object.

  1. Define a class named Car that also extends the Vehicle class. This class has an additional data field: the number of passengers. Include appropriate constructor(s) and accessors and mutators. Finally override the toString() method to return a string that includes all the information about a Car object.

  1. Directly inside the public class TestVehicle, define a method with the following header:

public static void displayObject(Vehicle object)

This method calls the toString() method of the Vehicle object to display the vehicle information.

  1. Create the main method that creates one Vehicle object, one Truck object, and one Car object. Then call thedisplayObject method three times to pass the three objects above, respectively, to display the vehicle information for each vehicle.

  1. The overall structure of the program file TestVehicle.java should be like the following:

public class TestVehicle

{

public static void main(String[] args)

{

}

public static void displayObject(Vehicle object)

{

}

}

class Vehicle

{

}

class Truck extends Vehicle

{

}

class Car extends Vehicle

{

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 14th East European Conference Adbis 2010 Novi Sad Serbia September 2010 Proceedings Lncs 6295

Authors: Barbara Catania ,Mirjana Ivanovic ,Bernhard Thalheim

2010th Edition

3642155758, 978-3642155758

More Books

Students also viewed these Databases questions

Question

3. Are our bosses always right? If not, what should we do?

Answered: 1 week ago

Question

2. What, according to Sergey, was strange at this meeting?

Answered: 1 week ago