Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a class called vehicle that has the manufacturer\'s name (type string), n

ID: 3837336 • Letter: C

Question

Create a class called vehicle that has the manufacturer's name (type string), number of cylinders in the engine (type int), and owner (type person given next) Then, create a class called Truck that is derived from vehicle and has the following additional properties: the load capacity in tons (type double since it may contain a fractional part) and towing capacity in pounds (type int) Be sure your class has a reasonable complement of constructors, accessor and mutator methods, and suitably defined equals and to string methods. Write a program to test all your methods. The definition of the class Person follows. Completing the definitions of the methods is part of this programming project. public class Person { public Person() { } public Person (String theName) { } public Person (Person the Object) { } public string getName () { } public void setName { } (String theName)() { } public String tostring public boolean equals object other) { } }

Explanation / Answer

Hi, Please find my implementation of Truck and Vehicle class.

######## Vehicle.java ########

public class Vehicle {

  

   // instance variables

   private String manufacturerName;

   private int numCylinder;

   private Person owner;

  

   public Vehicle(String maString, int n, Person person){

       manufacturerName= maString;

       numCylinder = n;

       owner = new Person(person);

   }

   public String getManufacturerName() {

       return manufacturerName;

   }

   public void setManufacturerName(String manufacturerName) {

       this.manufacturerName = manufacturerName;

   }

   public int getNumCylinder() {

       return numCylinder;

   }

   public void setNumCylinder(int numCylinder) {

       this.numCylinder = numCylinder;

   }

   public Person getOwner() {

       return owner;

   }

   public void setOwner(Person owner) {

       this.owner = owner;

   }

  

   @Override

   public String toString() {

       return "Manufaturer Name: "+manufacturerName+" "+

               "Number of Cylinder: "+numCylinder+" "+

               "Owner: "+owner.toString();

   }

  

   @Override

   public boolean equals(Object obj) {

       if(obj instanceof Vehicle){

           Vehicle v = (Vehicle)obj;

          

           if(manufacturerName.equals(v.manufacturerName) &&

                   numCylinder == v.numCylinder &&

                   owner.equals(v.owner))

               return true;

       }

      

       return false;

   }

}

######### Truck.java ##########

public class Truck extends Vehicle{

  

   private double loadCapacity;

   private int towingCApacity;

  

   public Truck(String maString, int n, Person person, double load, int tow){

       super(maString, n, person);

       loadCapacity = load;

       towingCApacity = tow;

   }

   public double getLoadCapacity() {

       return loadCapacity;

   }

   public void setLoadCapacity(double loadCapacity) {

       this.loadCapacity = loadCapacity;

   }

   public int getTowingCApacity() {

       return towingCApacity;

   }

   public void setTowingCApacity(int towingCApacity) {

       this.towingCApacity = towingCApacity;

   }

  

   @Override

   public boolean equals(Object obj) {

      

       if(obj instanceof Truck){

           Truck t = (Truck)obj;

          

           if(super.equals(t) && loadCapacity == t.loadCapacity &&

                   towingCApacity == t.towingCApacity)

               return true;

       }

      

       return false;

   }

  

   @Override

   public String toString() {

       return super.toString()+" "+

               "Load Capacity: "+loadCapacity+" "+

               "Towing Cpacity: "+towingCApacity;

   }

}

########## Test.java ##########

public class Test {

   public static void main(String[] args) {

      

       // creating Person Object

       Person p = new Person("Pravesh Kumar");

      

       // creating Truck Object

       Truck t = new Truck("Tata Motora", 21, p, 45.32, 45);

      

       System.out.println(t.toString());

   }

}

/*

Sample run:

Manufaturer Name: Tata Motora

Number of Cylinder: 21

Owner: Name = Pravesh Kumar

Load Capacity: 45.32

Towing Cpacity: 45

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote