求教: 关于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.