Polymorphic Greeter
Geoffrey Challen // 2020.9.0
Write a method name greet
that accepts a nullable Person
as an argument and returns a String
or null.
Depending on what kind of person it is, you should greet them differently:
- If the person is a
Professor
withname
"Geoff" you should greet them "Hi Professor Geoff" - If the person is a
Student
withname
"Friendly" you should greet them "Hey Friendly, you are not alone!" - If the person is a
Staff
, then they will have aString
role property. If their role is "advising" andname
is "Chuchu" you should greet them "Thanks Chuchu for all your help with advising".
All Person
s have a name property.
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.