Question: Implementation Requirements: Class Person: Constructor: A Person can have any name, but the age needs to be a value between 1 and 150 (inclusive). Throw

Implementation Requirements:
- Class Person:
- Constructor: A Person can have any name, but the age needs to be a value between 1 and 150 (inclusive). Throw an IllegalArgumentException if an invalid age is provided and include an error message stating that age needs to be from the range [1, 150].
- The method toString should return a string of the following format: {name}({age}) {name}, and {age} stand for the corresponding field values. Something similar is true whenever you see a reference to a field in curly braces throughout this assignment. E.g.: Chloe(24)
- Class Friend:
- The method chill should return a string of the following format {name} is chilling E.g., Ben is chilling
- The method play returns a string that depends on the number of friends in the array that is passed as an argument
- In case of an empty list (no friend): playing {hobby}
- In the case of one friend (list with one element): playing {hobby} with {friend}
- In the case of two friends (list with two friends): playing {hobby} with {friend1} and {friend2}
- If the argument list contains more than two friends: playing {hobby} with {friend1}, {friend2}, . . , and {friendN} Notice that the friends are separated by comma and space plus the word and before the last friend
- The method toString should return the same string as class Person plus a space and the hobby : {name}({age}) {hobby} E.g.: Chloe(24) GAMES
- Class Telemarketer:
- The method giveSalesPitch should return a string of the following format {name} pressures others to buy stuff E.g., Chap pressures others to buy stuff
- The overridden method annoy should return a string of the following format {name} annoys by giving a sales pitch E.g., Chap annoys by giving a sales pitch
- Class Insect:
- The method toString should return a string of the following format: {className}: {species} E.g.: Insect: wasp
- Class Butterfly:
- The field colors is a list of colors. The type of the list should be the generic interface List (Links to an external site.), not a class like ArrayList, which implements the interface. This provides flexibility and allows the clients to choose which type of list works best in the given context. You'll need the following import statement: import java.util.List;
- Class Butterfly has two constructors. One initializes the fields based on the individual field values provided; the other initializes the fields based on an existing Butterfly object. The latter creates a copy of the butterfly passed as an argument and is called a copy constructor (Links to an external site.). To avoid code duplication, implement one constructor by calling the other.
- Create defensive copies to protect the data integrity of Butterfly objects by ensuring that the fields of a butterfly can't be changed from another class. At first sight, it might seem that a Butterfly object can't be changed because the class Butterfly doesn't provide setters nor other mutators. However, that is not necessarily the case. Why not? Because class Butterfly has a mutable field: colors. Here is how the mutable field could affect the butterfly: The client could provide a list of colors as an argument to the Butterfly constructor but change the list later on. If we assign the list to the field, we make the field link to the object that is possibly changed later on. To prevent such changes from affecting the butterfly, a defensive copy needs to be made. In other words: the field should not link to the List object provided by the user but to a new List object that includes the same colors (a defensive copy). Similar caution is needed when returning a mutable field. In our case, this affects the method getColors. If you return the field colors, a reference to the object is returned, and the client could use that reference to add or remove colors and thus change the butterfly. To avoid that, a defensive copy needs to be created and returned.
- The method toString should return a string of the following format: {species} [{color1}, {color2}, . . , {colorN}] {color1}, {color2}, {colorN} are substituted with the individual colors in the list. If no color has been provided, the empty brackets are added to the string. E.g.: Monarch [yellow, orange, black] E.g.: Morpho [blue] E.g.: Phoebis []
- Class Mosquito:
- The method buzz should return the string of the following format: {species} buzzing around E.g., Culex tarsalis buzzing around
- The overridden method annoy should return the string buzz buzz buzz
- Class PeskyMosquito:
- The method bite should return the string sucking blood
- Overriding the method equals: The method equals is not included in the UML class diagram. That's because I want you to determine where to override it to provide the following desired behavior:
- Desired behavior: I want to be able to determine whether two friends are equal at runtime. In other words: When I create two Friend objects, and both friends have the same name, the same age, and the same hobby, then those two friends should be equal. Otherwise, they should not be equal.
Test Client:
Add a class named NuisanceApp to the project. It is the test client and includes the main method. For details like titles, descriptions, empty lines to group the output, refer to the Expected Output below. As the name suggests, this is how your output should look like.
- Test Persons:
- Create an array that includes three friends: Juan 27 hobby music, Kate 27 hobby sports, and Alex 21 hobby music.
- Print a title. Then use a loop to print the three array elements.
- Compare friend1 with friend2 and friend 1 with friend3 and print the results.
- Create a new friend object with the same information as before: Kate 27 hobby sports Note that assigning the original friend to a new variable won't create a new object. Compare friend2 with the new friend and print the result.
- Create a telemarketer: Fritz 25 and print the telemarketer
- Test Insects:
- Create a mosquito: species Aedes vexans Create a pesky mosquito: species Anopheles walkeri Create a butterfly: species Swallowtail and colors yellow, black, blue Use the copy constructor to create a second butterfly that is also a Swallowtail with the same colors.
- Create an array of insects and initialize it with the mosquito, the pesky mosquito, and both butterflies
- Print a title. Then use a loop to print the insects.
- Test interface Nuisance
- Create an array of type Nuisance. It includes the telemarketer, the mosquito, and the pesky mosquito.
- Print a title. Then loop through the array elements. For each of the array elements, do the following:
- if it is a mosquito, buzz
- if it is a pesky mosquito, bite
- regardless, which nuisance it is, annoy
You might have noticed that this test client tests only some of the requirements. The JUnit tests provide more comprehensive testing of the individual methods.
Example Output
3 Friends: friend1: Juan(27) MUSIC friend2: Kate(27) SPORTS friend3: Alex(21) MUSIC friend1 equals friend2: false friend1 equals friend3: false friend2 equals new friend: true telemarketer: Fritz(25) 4 Insects: Mosquito: Aedes vexans PeskyMosquito: Anopheles walkeri Swallowtail [yellow, black, blue] Swallowtail [yellow, black, blue] 3 Nuisances: Fritz annoys by giving a sales pitch Aedes vexans buzzing around buzz buzz buzz Anopheles walkeri buzzing around sucking blood buzz buzz buzz
Insect Person name : String age : int + Person(name : String, age : int) + getName(): String + getAge(): int + toString(): String interface >> Nuisance annoy(): String species : String + Insect ( species : String) + getSpecies(): String + toString(): String A A Mosquito Telemarketer + buzz(): String give SalesPitch(): String Butterfly - colors : List
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
