Programming Assignment #56
Code
/// Name: Dylan Sleeper
/// Period: 6
/// Program Name: Fortune Cookie
/// File Name: FortuneCookies.java
/// Date Finished: 10/22/2015
import java.util.Random;
public class FortuneCookie{
public static void main(String[] args){
String fortune = "";
Random ran = new Random();
int r = ran.nextInt(5);
if(r == 0){
fortune = "\"Stay in school.\"";
}
else if(r == 1){
fortune = "\"Stay at home.\"";
}
else if(r == 2){
fortune = "\"Eat lots of fortune cookies.\"";
}
else if(r == 3){
fortune = "\"You got no fortune. That's odd...\"";
}
else if(r == 4){
fortune = "\"Have a nice day!\"";
}
System.out.println("Fortune cookie says: " + fortune);
System.out.print(" ");
for(int i = 0; i < 5; i++){
int num = ran.nextInt(54) + 1;
System.out.print(num + " - ");
}
int num = ran.nextInt(54) + 1;
System.out.print(num);
System.out.println();
}
}
Outputs