Question: 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
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.1Truck 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.
Listing 8.1
Person Class
public class Person
{
String name;
public Person( )
{
name = "No name yet";
}
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
3.39 Rating (165 Votes )
There are 3 Steps involved in it
public class Vehicle public String manfacname public int cylinders public Person owner public Vehicl... View full answer
Get step-by-step solutions from verified subject matter experts
Document Format (1 attachment)
1013-C-S-O-S (710).docx
120 KBs Word File
