Quote:
Originally Posted by rfreder2
.// an implementation of the abstract data type "person"
public class Person {
// data members
private String firstName;
private String lastName;
private String middleName;
// default constructor
public Person() {
setName("", "");
}
// constructor with parameters
public Person(String first, String middle, String last) {
setName(first, middle, last);
}
// accessor method for first name
public String getFirstName() {
return firstName;
}
// accessor method for middle name
public String getMiddleName() {
return middleName;
}
// accessor method for last name
public String getLastName() {
return lastName;
}
// mutator method for first name
public void setFirstName(String first) {
firstName = first;
}
// mutator method for middle name
public void setMiddleName(String middle) {
middleName = middle;
}
// mutator method for last name
public void setLastName(String last) {
lastName = last;
}
// mutator method for complete name
public void setName(String first, String last) {
firstName = first;
middleName= middle;
lastName = last;
}
// override the default definition of toString
public String toString() {
return(firstName + middleName + lastName);
}
}
i've been workin on it and i stuck on this could some body help me with Adding a method isLastName to check whether a given last name is the same as
the last name of some Person object. Write a similar methods, isFirstName and isMiddleName, for the first name and the middle name.
Please use code tags when posting your code
First your code will not compile like that. You need to overload your setName method for the middle name.i.e setName(first, middle, last); takes 3 Strings, but you do not have such a method.
For the other methods, you need to know how to compare 2 Strings for equality. The method would return true if they are equal and false otherwise.