Question: Create a public class named Visitor that provides a single class method named visit. visit should accept a single parameter, a Place to visit, and
Create a public class named Visitor that provides a single class method named visit. visit should accept a single parameter, a Place to visit, and return a String, a remark on how to visit that place. Depending on which subclass of Place it is you should respond differently. Every place has a name you can retrieve using getName. assert that the passed place is notnull
If the place is a Buildingfor instance, one named "Siebel"you should respond "Let's go to the Siebel building."
If the place is a Parkfor instance, one named "West Side"you should respond "Let's visit West Side park."
If the place is a Restaurant, then it will have a String property cuisine you can retrieve using getCuisine. For example, if the cuisine is "thai" and the name is "Thara Thai", you should respond "Let's try thai food at Thara Thai."
If the place is not one of the kinds described above, return "Whoa, mysterious!". Do not solve this problem using method overloading! And do not hardcode the answers. Your solution should work for any Building, Park, or Restaurant.
Note that many restaurants are also buildings. The tendency of real entities to resist strict classification is one of the limitations of Java's object model.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
