Connecting Tech Pros Worldwide Forums | Help | Site Map

Can somebody please help me finish this i started but can't finish

Newbie
 
Join Date: Sep 2006
Posts: 2
#1: Oct 2 '06
// an implementation of the abstract data type "person"

public class Person {
// data members
private String firstName;
private String lastName;

// default constructor
public Person() {
setName("", "");
}


// constructor with parameters
public Person(String first, String last) {
setName(first, last);
}


// accessor method for first name
public String getFirstName() {
return firstName;
}


// mutator method for first name
public void setFirstName(String first) {
firstName = first;
}


// mutator method for complete name

public void setName(String first, String last) {
firstName = first;
lastName = last;


}

// override the default definition of toString
public String toString() {
return(firstName + " " + lastName);
}


}

Modifications and additions to be made:

1. Add the data member middleName to store the person’s middle name.
2. Modify the two constructors, along with toString and setName to include a
middle name.
3. Add the accessor methods getLastName and getMiddleName.
4. Add the mutator methods setMiddleName and setLastName.
5. Add 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.
6. Add the method equals that returns true if two objects have the same first,
middle and last names.
7. Add the method makeCopy that copies the instance variables of a Person object
into another Person object.
8. Add the copy constructor.

Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#2: Oct 2 '06

re: Can somebody please help me finish this i started but can't finish


Quote:

Originally Posted by rfreder2

// an implementation of the abstract data type "person"

public class Person {
// data members
private String firstName;
private String lastName;

// default constructor
public Person() {
setName("", "");
}


// constructor with parameters
public Person(String first, String last) {
setName(first, last);
}


// accessor method for first name
public String getFirstName() {
return firstName;
}


// mutator method for first name
public void setFirstName(String first) {
firstName = first;
}


// mutator method for complete name

public void setName(String first, String last) {
firstName = first;
lastName = last;


}

// override the default definition of toString
public String toString() {
return(firstName + " " + lastName);
}


}

Modifications and additions to be made:

1. Add the data member middleName to store the person’s middle name.
2. Modify the two constructors, along with toString and setName to include a
middle name.
3. Add the accessor methods getLastName and getMiddleName.
4. Add the mutator methods setMiddleName and setLastName.
5. Add 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.
6. Add the method equals that returns true if two objects have the same first,
middle and last names.
7. Add the method makeCopy that copies the instance variables of a Person object
into another Person object.
8. Add the copy constructor.

Let's clear things a bit first.
Did you really start this?
If you did, I find it hard to believe that you cannot even start the next step.
Newbie
 
Join Date: Sep 2006
Posts: 2
#3: Oct 2 '06

re: Can somebody please help me finish this i started but can't finish


.// 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.
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#4: Oct 2 '06

re: Can somebody please help me finish this i started but can't finish


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.
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#5: Oct 3 '06

re: Can somebody please help me finish this i started but can't finish


Quote:

Originally Posted by r035198x

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.

Hint: The method has already been written as part of the String class
Reply


Similar Java bytes