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

Problem 3, page 662. I am trying to print out the results, but Im getting an err

ID: 3857364 • Letter: P

Question

Problem 3, page 662. I am trying to print out the results, but Im getting an error message. Here is my code. my professor said I need to call the overloaded constructor in parent class via super. i dont know what that means. can yiou help me out. I have 4 files, Person.java, Vehicle.java, truck.java, and truckdemo.java


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(int v){

       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));

   }

  

  

}

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);

   capacity=loadCapacity;

   towing=towingCapacity;

  

      

   }

  

   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 OtherTruck, Vehicle SecondVehicle){

       return    (super.equals(SecondVehicle)&& (this.loadCapacity==OtherTruck.loadCapacity) &&

               (this.towingCapacity==OtherTruck.towingCapacity) &&

               (this.getOwner().equals(OtherTruck)));

           }

  

   public void writeOutput1(){

       super.writeOutput();

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

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

   }

  

}

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("Scott", "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));

      

      

   }

  

}

Explanation / Answer


Note : Could you please check the output .If you required any changes Just intimate.I will modify it.Thank You.

______________________

Person.java

public class Person {
private String name;

public Person() {

}

public Person(String name) {
super();
this.name = name;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

}

__________________

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));
}

}

_______________________

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(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(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);
}

}

_____________________

TruckDemo.java

public class TruckDemo {

public static void main(String[] args) {

Person name = new Person("Cliff");
Truck attributes = new Truck("Scott", "Mazda", 4, 400, 500);
attributes.writeOutput1();
System.out.println();
Truck second = new Truck("Scott", "Mazda", 4, 400, 500);
second.writeOutput1();

System.out.println(" Does first truck attributes equal " + "second truck attributes? " + attributes.equals(second));

}

}

____________________

Output:


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

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

Does first truck attributes equal second truck attributes? true

______________Thank You

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