Question: public class Person { / / Fields private String name; private boolean hasDriverLicense; private int age; private int height; / / Constructor public Person (

public class Person {
// Fields
private String name;
private boolean hasDriverLicense;
private int age;
private int height;
// Constructor
public Person(String name, boolean hasDriverLicense, int age, int height){
this.name = name;
this.hasDriverLicense = hasDriverLicense;
this.age = age;
this.height = height;
}
// Getters
public String getName(){
return this.name;
}
public boolean hasDriverLicense(){
return hasDriverLicense;
}
public int getAge(){
return age;
}
public int getHeight(){
return height;
}
// Clone method
public Person clone(){
Person newPerson = new Person(this.name, this.hasDriverLicense, this.age, this.height);
return newPerson;
}
// Equals method
@Override
public boolean equals(Object o){
if (o == null){
return false;
}
if (o == this){
return true;
}
if(o instanceof Person){
Person person =(Person) o;
if(person.getName().equals(this.name)){
if(person.hasDriverLicense==this.hasDriverLicense){
if(person.getAge()==this.age){
if(person.getHeight()==this.height){
return true;
}
}
}
}
}
return false;
}
// ToString method
@Override
public String toString(){
if(hasDriverLicense == true){
return String.format("Person [name=%s | age=%02d | height=%02d | has license%s license]",
name, age, height);
}
return String.format("Person [name=%s | age=%02d | height=%02d | no license%s license]",
name, age, height);
}
} fix code

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 Programming Questions!