Question: Java Create a base class called Vehicle that has the manufacturers name (type String ), # of cylinders in the engine (type int ), and
Java
Create a base class called Vehicle that has the manufacturers name (type String), # of cylinders in the engine (type int), and owner (type Person from Sakai Week 11 Source Code folder).
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 (Vehicle: 0- and 3-parameter constructors; Truck: 0- and 5-parameter constructors) and accessor methods (getters and setters for all instance variables in each class). Trucks constructors should call Vehicles constructors using super().
Write a driver program (no pun intended) that tests all your methods. It will be easier to test the constructors if you write a toString method for both classes. You can test the setters by calling them in the constructors, and the getters by calling them in the toString methods; use Persons getName to get their name in the Vehicle toString method. Hint: if you use all of the setters in the constructors and all of the getters in the toString methods then your driver program only has to create objects using the two constructors in each class and print those objects in order to test everything.
Person source code
public class Person { private String name; public Person( ) { name = "No name yet"; // can also say this("No name yet"); // calls the other constructor } public Person(String initialName) { name = initialName; } public void setName(String newName) { name = newName; } public String getName( ) { return name; } public void writeOutput( ) { System.out.println("Name: " + name); } public boolean hasSameName(Person otherPerson) { return this.name.equalsIgnoreCase(otherPerson.name); } } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
