How to do this task?

Look into the else if and else structures. That may help with your question.

Please use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.