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

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

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!