008-001-008
void Method: Greeting Message Display
Medium
Problem Description
Method Return Value: Greeting Message Generation
In this problem, you will define a greet method in a Greeter class that accepts a time-of-day parameter and returns the corresponding greeting string.
Learning Objective: Understand how to define and call a String-returning method that accepts parameters
Specifications
Greeter Class
Define the following method:
String greet(String timeOfDay): Returns the greeting string for the given time of day"morning"→"Good morning!""afternoon"→"Good afternoon!""evening"→"Good evening!""night"→"Good night!"
Input / Output
- Read one line from standard input: the time of day (
morning/afternoon/evening/night) - Print the corresponding greeting string
Example
Input: morning
Output: Good morning!
Input: afternoon
Output: Good afternoon!
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up