Fabulous Feb Offer: Flat 70% Off + 20-days Extra Lab + 10% Addl. Off on All Courses | Use Coupon Code FAFB | Expires in

  Enroll Now


24 / 52

Scala - Assessment - Display Greeting Message

Let's take a look at a program which will return 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 return "Good Morning" If we execute Greet.greet(12), then it should return "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".