Learning is Evolving |Flat 25% off on all courses | Use coupon code LEARN25 During checkout |

 Enroll Now


24 / 52

Scala - Assessment - Display Greeting Message

Let's take a look at a program which will print different greeting messages according to the time of the day.

We will write a Scala program with the main class name of Greet having a function named greet which would return different greeting messages as described below, according to the time input to the function.

Input time - 4 to till before 12 : Message Output - "Good Morning"
Input time - 12 to till before 16 : Message Output - "Good Afternoon"
Input time - 16 to till before 21 : Message Output - "Good Evening"
Input time - 21 to till before 4 : Message Output - "Good Night"

Example Usage:

If we execute Greet.greet(5), then it should print "Good Morning" If we execute Greet.greet(12), then it should print "Good Afternoon" and so on...

  • Write the code in Jupyter and press Shift + Enter.

  • Test the function with various inputs to make sure that it is returning the outputs as per requirements.

  • Click on "Submit Answer".