Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with my Person Class PLEASE provide corrected codes if possible. My code: public class Person { private String name; private boolean hasDriverLicense;

I need help with my Person Class
PLEASE provide corrected codes if possible.
My code:
public class Person
{
private String name;
private boolean hasDriverLicense;
private int age;
private int height;
public Person(String name, boolean hasDriverLicense, int age, int height)
{
this.name = name;
this.hasDriverLicense = hasDriverLicense;
this.age = age;
this.height = height;
}
public String getName()
{
return name;
}
public boolean hasDriverLicense()
{
return hasDriverLicense;
}
public int getAge()
{
return age;
}
public int getHeight()
{
return height;
}
public Person clone()
{
return new Person(name, hasDriverLicense, age, height);
}
@Override
public boolean equals(Object o)
{
if (this == o) return true;
if (o == null || getClass()!= o.getClass()) return false;
Person person =(Person) o;
return hasDriverLicense == person.hasDriverLicense &&
age == person.age &&
height == person.height &&
name.equals(person.name);
}
@Override
public String toString()
{
return String.format("Person [name=%s | age=%02d | height=%02d | has license/%s]",
name, age, height, hasDriverLicense ? "license" : "no license");
}
}
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine M. Ricardo

1st Edition

0763733148, 978-0763733148

More Books

Students also viewed these Databases questions