Create a base class called Vehicle that has the manufacturer’s name (type String), number of cylinders in the engine (type int), and owner (type Person given in Listing 8.1). Then create a class called Truck that is derived from Vehicle and has additional properties: the load capacity in tons (type double, since it may contain a fractional part) and towing capacity in tons (type double).
Give your classes a reasonable complement of constructors and accessor methods, and an equals method as well. Write a driver program (no pun intended) that tests all your methods.
This project requires most of the same type of thinking as previous problems to write constructors, accessor and mutator methods except that one of Vehicle’s data members is an instance of a class rather than a fundamental data type (owner is an instance of the class Person). Operations involving the owner, therefore, must use the methods of the Person class. NOTE: early editions of the text may have an error in the definition of sameName()in Person. If the method definition is
```
return (this.name.equalsIgnoreCase(otherPerson.name));```
it should be changed to
```
return (this.name.equalsIgnoreCase(otherPerson.gettName()));
```
The sameName() method is called in the code for the equals method of Vehicle to test if two vehicles have the same owner.
A methodical approach that makes this problem manageable is to develop one method in Vehicle, then write a test for the method in VehicleTest and run it. Add the next method to Vehicle only when VehicleTest runs successfully. When all the methods for Vehicle have been written and tested with VehicleTest, then do a similar piece-wise development for Truck and TruckTest, first testing all the methods inherited from Vehicle, then writing one new method at a time and testing it before going on to the next.
See the code in Vehicle.java, VehicleTest.java, Truck,java, and TruckTest.java.
You might also like to view...
Which of the following standards are related to the operation of a PAD?
a. X.3 b. X.28 c. X.29 d. all of the above
What is the binary code that can represent most currently used language characters and is the standard used on the Internet?
a.ASCII b.Base 2 c.International standards d.Unicode
A stub is the beginning of a final function that can be used as a placeholder for the final unit until the unit is completed.
Answer the following statement true (T) or false (F)
If you want to insert the page number in an existing header or footer, first position the insertion point in the header or footer at the location where you want the page number to appear. Click the Page Number button, point to Current Position, and then choose a style.
Answer the following statement true (T) or false (F)