Skip to main content
0 online
theremin May 3, 2006

Quite a lot to do with this one.. so Far I have a class that looks like public class Person { private String firstName; private String lastName; public Person() { firstName = ""...

iwz May 3, 2006

Well, here's something to get you started: "So how would I set the last name only" q[Person person = new Person(); person.setLastName("Smith");]q or q[Person person = new Person(null, "Smi...

theremin May 3, 2006

That is kind. Thank you.

iwz May 3, 2006

here's a bonus equals method you can add to the Person class: q[public boolean equals( Object o ) { if ( this == o ) return true; if ( o == null || getClass() != o.getClas...

theremin May 3, 2006

Well this is what I did.. tell me if it looks right. It compiles without errors at least. hehe public class Person { private String firstName; private String middleName; private String ...

iwz iwz

Looks pretty good. I'd change a couple of things tho.

== is not proper for comparing Strings. use .equals() instead.

so this firstName == otherPerson.firstName && lastName == otherPerson.lastName should be like this firstName.equals( otherPerson.firstName) && lastName.equals(otherPerson.lastName)

Also, the makeCopy(Person) method may be more appropriate as a constructor instead of a method.

public Person( Person person )
{
firstName = person.firstName;
middleName = person.middleName;
lastName = person.lastName;
}

Also, for the getCopy method, take a look at the Cloneable interface, and the clone() method. It may give you a cleaner implementation. But that depends on your requirements, of course.

theremin thereminOG 2002

Oh, we didn't talk about a clone() method yet. Thanks for all the help as usual.

Welcome Back to eZabel

It's been a while. Here's what's new.

eZabel Lore

A complete history of our community — stats, Hall of Fame, legendary threads, and more.

View the Lore →

Everything Preserved

All 225,969 pieces of content from 2000–2014 are here — forums, messages, journals, photos, polls, and events.

💎

Gems

Spot something you love — a legendary comment, a classic thread, a great photo? Log in and click the diamond icon to mark it as a Gem. Add a note about why it's special. The best stuff surfaces on the Gems page.