Colorado State University

CS160: Foundations in Programming

Lab 7
Java programming


The purpose of this exercise is
Instructions: Your GTA will lead you through the following:
     

Fortune Teller

Write a program that asks the user for any number and displays one of five different fortunes based on the remainder obtained when the number is divided by 5. Note that when any number is divided by 5, there can be only 5 remainders, which are 0,1,2,3,4. Corresponding to those numbers there are 5 different fortunes, which you are free to choose! Your program will output the appropriate fortune, given a number.

First write a program Lab7IfElse.java that uses if-else statement to implement the above.
Then write another program Lab7SwitchCase.java that uses switch-case statement to implement the same.


Example
Suppose, for the numbers 0,1,2,3,4 we have the  following 5 fortunes to display: 

0Giving will make you smile
1Absence makes the heart grow fonder
2Keep your friends close and your enemies closer
3Let your heart guide you
4Don't be so hard on yourself, we all make mistakes
Below are a number of sample outputs from the program :

Enter a number : 56 Your today's fortune is : Absence makes the heart grow fonder

Enter a number : 34 Your today's fortune is : Don't be so hard on yourself, we all make mistakes

Enter a number : 1897 Your today's fortune is : Keep your friends close and your enemies closer


You must show your GTA your work to get credit for this lab completion.
© 2008 CSU