求教: 關於java, 真是不太明白

來源: 2005-03-22 22:46:25 [舊帖] [給我悄悄話] 本文已被閱讀:

我是新手, 在自學java, 還是有些糊塗, 請問誰知道怎麽寫啊?
關鍵是第7步不知道怎麽寫

Write a class Name that stores a person's first, middle, and last names and provides the following methods:

1. public Name(String first, String middle, String last) -- constructor. The name should be stored in the case given; don't convert to all upper or lower case.

2. public String getFirst() -- returns the first name.

3. public String getMiddle() -- returns the middle name.

4. public String getLast() -- returns the last name.

5. public String firstMiddleLast() -- returns the person's full name in order, e.g., "Mary Jane Smith".

6. public String lastFirstMiddle() -- returns the person's full name with the last name first followed by a comma, e.g., "Smith, Mary Jane".

7. public boolean equals(Name otherName) -- returns true if this name is the same as otherName. Comparisons should not be case sensitive. (Hint: There is a String method equalsIgnoreCase that is just like the String method equals except it does not consider case in doing its comparison.)

8. public String initials() -- returns the person's initials (a 3-character string). The initials should be all in upper case, regardless of what case the name was entered in.

9. public int length() -- returns the total number of characters in the full name, not including spaces.