beyondgrader.com Logo
DemoBrowseAboutTeamLogin

Polymorphic Greeter

Geoffrey Challen // 2020.9.0

Create a public class named Greeter that provides a single class method named greet. greet should accept a single parameter, a Person to greet, and return a String, the greeting. Depending on what kind of person it is, you should greet them differently:

  • If the person is a Professor—for instance, one named "Geoff"—you should greet them "Hi Professor Geoff"
  • If the person is a Student—for instance, one named "Friendly"—you should greet them "Hey Friendly, you are not alone!"
  • If the person is a Staff, then they will have a String role you can retrieve using getRole. For example, if their role is "advising" their name is "Chuchu", you should greet them "Thanks Chuchu for all your help with advising".

All Persons have a name that you can retrieve using getName. If the person is null or not one of the kinds of people described above, return null. Do not solve this problem using method overloading. And do not hard-code the answers. Your solution should work for any Professor, Student, or Staff.