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

I have these three files, the TruckDemo.java file should spit back a answer of t

ID: 3857705 • Letter: I

Question

I have these three files, the TruckDemo.java file should spit back a answer of true, but im getting a false statement, can you help show me what I got wrong?? this problem is page 662, number 3.
***************** Vehicle.java

public class Vehicle {

   private String manufactureName;

   private int cylinders;

   private Person owner;

  

   Vehicle(){

      

   }

  

   public Person getOwner(String p){

       return new Person(p);

      

   }

  

   public Vehicle(String make, int v, Person owner1 ){

  

   this.owner=owner1;

   this.cylinders=v;

   this.manufactureName=make;

   }

  

   public void setOwner(Person name){

       name=owner;

   }

   public void setmanufactureName(String manufacture){

       manufactureName=manufacture;

   }

  

   public void setCylinders(int type){

       cylinders=type;

   }

  

   public Person getOwner(){

       return owner;

      

   }

   public String getmanufacture(String m){

       return this.manufactureName;

   }

  

   public int getCylinders(){

       return this.cylinders;

   }

  

   public void writeOutput(){

       System.out.println("Owner name: "+getOwner().getName());

       System.out.println("Vehicle type: "+manufactureName);

       System.out.println("V-"+cylinders);

   }

  

   public boolean equals(Vehicle SecondVehicle, Person owner){

       return   (super.equals(getOwner()) &&

               (this.manufactureName.equals(SecondVehicle)) &&

               (this.cylinders==SecondVehicle.cylinders));

           

   }

  

  

}

********** end of Vehicle.java

********Start of Truck.java

public class Truck extends Vehicle{

   private double loadCapacity;

   private double towingCapacity;

  

   public Truck(){

       super();

       loadCapacity=100.00;

       towingCapacity=200.00;

   }

  

  

   public Truck(String owner1, String make, int v,

               double capacity, double towing ){

   //super.getOwner(owner1);

   //super.getCylinders(v);

   //super.getmanufacture(make);

   super(make,v,new Person(owner1));

   this.loadCapacity=capacity;

   this.towingCapacity=towing;

  

      

   }

  

   public void setloadCapacity(double capacity){

       loadCapacity=capacity;

   }

  

   public void settowingCapacity(double towing){

       towingCapacity=towing;

   }

  

   public double getloadCapacity(){

       return loadCapacity;

   }

  

   public double gettowingCapacity(){

       return towingCapacity;

   }

  

   public boolean equals1(Truck SecondVehicle){

           if    (this.getOwner().getName().equals(SecondVehicle.getOwner().getName()) &&

               this.getCylinders()==SecondVehicle.getCylinders() &&

               this.getloadCapacity()==SecondVehicle.getloadCapacity() &&

               this.gettowingCapacity()==SecondVehicle.gettowingCapacity())

              

           return true;

           else

               return false;

           }

  

  

   public void writeOutput1(){

       super.writeOutput();

       System.out.println("Truck load capacity: "+loadCapacity);

       System.out.println("Truck towing capacity: "+towingCapacity);

   }

  

}

******** end of Truck.java

*******start of TruckDemo.java

public class TruckDemo {

   public static void main(String[] args) {

       // TODO Auto-generated method stub

       //Person owner = new Person("Scott");

       //Vehicle first = new Vehicle("Mazda", 4, "Scott");

       //owner.writeOutput();

       //first.writeOutput();

       System.out.println();

      

       //String owner1, String make, int v,

       //double capacity, double towing

      

      

       Truck attributes = new Truck("Chris", "Mazda", 4, 400, 500);

       //attributes.writeOutput();

       attributes.writeOutput1();

       System.out.println();

       Truck second = new Truck("Scott", "Mazda", 4,400,500);

       //Person name = new Person("Cliff");

       second.writeOutput1();

       System.out.println(" Does first truck attributes equal "

               + "second truck attributes? "+attributes.equals(second));

      

      

  

  

   }

}

***** end of TRuckDemo.java

Explanation / Answer

public class Person {

private String name;

/**

* @param name

*/

public Person(String name) {

this.name = name;

}

/**

* @return the name

*/

public String getName() {

return name;

}

/**

* @param name

* the name to set

*/

public void setName(String name) {

this.name = name;

}

@Override

public boolean equals(Object other) {

if (other instanceof Person) {

Person p = (Person) other;

return this.getName().equals(p.getName());

} else

return false;

// TODO Auto-generated method stub

}

}

public class Vehicle {

private String manufactureName;

private int cylinders;

private Person owner;

Vehicle() {

}

public Person getOwner(String p) {

return new Person(p);

}

public Vehicle(String make, int v, Person owner1) {

this.owner = owner1;

this.cylinders = v;

this.manufactureName = make;

}

public void setOwner(Person name) {

name = owner;

}

public void setmanufactureName(String manufacture) {

manufactureName = manufacture;

}

public void setCylinders(int type) {

cylinders = type;

}

public Person getOwner() {

return owner;

}

public String getmanufacture(String m) {

return this.manufactureName;

}

public int getCylinders() {

return this.cylinders;

}

public void writeOutput() {

System.out.println("Owner name: " + getOwner().getName());

System.out.println("Vehicle type: " + manufactureName);

System.out.println("V-" + cylinders);

}

public boolean equals(Object other) {

if (other instanceof Vehicle) {

Vehicle SecondVehicle = (Vehicle) other;

Person owner = SecondVehicle.getOwner();

return (owner.equals(this.getOwner())

&& (this.manufactureName.equals(SecondVehicle)) && (this.cylinders == SecondVehicle.cylinders));

} else

return false;

}

}

public class Truck extends Vehicle {

private double loadCapacity;

private double towingCapacity;

public Truck() {

super();

loadCapacity = 100.00;

towingCapacity = 200.00;

}

public Truck(String owner1, String make, int v, double capacity,

double towing) {

// super.getOwner(owner1);

// super.getCylinders(v);

// super.getmanufacture(make);

super(make, v, new Person(owner1));

this.loadCapacity = capacity;

this.towingCapacity = towing;

}

public void setloadCapacity(double capacity) {

loadCapacity = capacity;

}

public void settowingCapacity(double towing) {

towingCapacity = towing;

}

public double getloadCapacity() {

return loadCapacity;

}

public double gettowingCapacity() {

return towingCapacity;

}

public boolean equals(Object other) {

if (other instanceof Truck) {

Truck SecondVehicle = (Truck) other;

if ((this.getOwner().getName().equals(SecondVehicle.getOwner()

.getName()))

&& (this.getCylinders() == SecondVehicle.getCylinders())

&& (this.getloadCapacity() == SecondVehicle

.getloadCapacity())

&& (this.gettowingCapacity() == SecondVehicle

.gettowingCapacity()))

return true;

else

return false;

} else

return false;

}

public void writeOutput1() {

super.writeOutput();

System.out.println("Truck load capacity: " + loadCapacity);

System.out.println("Truck towing capacity: " + towingCapacity);

}

}

public class TruckDemo {

public static void main(String[] args) {

// TODO Auto-generated method stub

// Person owner = new Person("Scott");

// Vehicle first = new Vehicle("Mazda", 4, "Scott");

// owner.writeOutput();

// first.writeOutput();

System.out.println();

// String owner1, String make, int v,

// double capacity, double towing

Truck attributes = new Truck("Chris", "Mazda", 4, 400, 500);

// attributes.writeOutput();

attributes.writeOutput1();

System.out.println();

Truck second = new Truck("Chris", "Mazda", 4, 400, 500);

// Person name = new Person("Cliff");

second.writeOutput1();

System.out.println(" Does first truck attributes equal "

+ "second truck attributes? " + attributes.equals(second));

}

}

OUTPUT:


Owner name: Chris
Vehicle type: Mazda
V-4
Truck load capacity: 400.0
Truck towing capacity: 500.0

Owner name: Chris
Vehicle type: Mazda
V-4
Truck load capacity: 400.0
Truck towing capacity: 500.0

Does first truck attributes equal second truck attributes? true

NOTE: you have to overload the method equals(Object ) in the Truck class,