Write a toString function that produces a String representation of a Person object.
It is best to have a separate testing procedure for it in PersonTester. The representation it produces is illustrated by three examples:
"male person Hamlet, Prince of Denmark. Status: I see dead people!. Born 1939. Best friend of 122 people."
"female person Florence Macbeth. Status: geez. Could use some hand soap here!!!!!. Born 1990. Best friend of 1 person."
"male person Caliban. Born 1950. Best friend of 0 people."
Here are the rules.
0. You may not use an if-statement. This function is easily written with a single return statement that consists of the catenation of several parts. For readability, put each part on a separate line. You will use conditional expressions,and we give you one of them below.
1. Exactly one blank appears between words, with the exception of the status message and display name, which can have any spacing within them.
2. Get the gender with a blank after it using this conditional expression: (isMale() ? "male " : "female ")
3. The word "person" is followed by a blank, the person's display name, and a period '.'.
4. The word "Status", the status message, and following period appear only if the status is not null. Use a conditional expression.
5. The birth year always appears.
6. The number of people calling this person their best friend and following period appear as shown in the examples. If the number of people calling this person their best friend is 1,
"person" appears; otherwise, "people" appears. Use a conditional expression.
7. Information about the male and female friends does not appear.
In testing toString, you need enough test cases to ensure that each different way of evaluating a conditional expression is tested. For example, to test whether the gender appears correctly, you need at least two test cases, for a female Person and for a male Person.
When making up a test case, construct it by hand, based on what you read above. Then, write an assertEquals statement that compares this expected value to the computed one. This is what we did.