Need help with this fortune telling java program: It works sometimes depending o
ID: 3562875 • Letter: N
Question
Need help with this fortune telling java program: It works sometimes depending on what the user inputs:
for example this is an outcome that I received and not sure how to fix it.
select a number: 123
3
select the color from red,blue,green,yellow
Enter 1 for RED
2 for BLUE
3 for GREEN
4 for YELLOW
3
And it just ends there with out spitting out a fortune. Also I just wanted the user to pick a number between 0-2. Need help fixing that too.
import java.util.Random;
import java.util.Scanner;
public class Fortune_Tell {
static Random rand=new Random();
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
// variables
int choice;
int color = 0,number = 0;
// if choice is 0 -> 0,1,2
// if choice is 1 -> 1,2,3
// if choice is 2 -> 2,3,4
// if choice is 3 -> 3,4,5
// if choice is 4 -> 4,5,6
choice=rand.nextInt(4);
switch(choice)
{
case 0: System.out.println("select a number: "+choice+""+(choice+1)+" "+ " "+(choice+2));number=sc.nextInt();
System.out.println("select the color from red,blue,green,yellow");
System.out.println("Enter 1 for RED 2 for BLUE 3 for GREEN 4 for YELLOW");
color=sc.nextInt();
break;
case 1:System.out.println("select a number: "+choice+""+(choice+1)+""+(choice+2));
number=sc.nextInt();
System.out.println("select the color from red,blue,green,yellow");
System.out.println("Enter 1 for RED 2 for BLUE 3 for GREEN 4 for YELLOW");
color=sc.nextInt();
break;
case 2:System.out.println("select a number: "+choice+""+(choice+1)+""+(choice+2));
number=sc.nextInt();
System.out.println("select the color from red,blue,green,yellow");
System.out.println("Enter 1 for RED 2 for BLUE 3 for GREEN 4 for YELLOW");
color=sc.nextInt();
break;
case 3:System.out.println("select a number: "+choice+""+(choice+1)+""+(choice+2));
number=sc.nextInt();
System.out.println("select the color from red,blue,green,yellow");
System.out.println("Enter 1 for RED 2 for BLUE 3 for GREEN 4 for YELLOW");
color=sc.nextInt();
break;
case 4:System.out.println("select a number: "+choice+""+(choice+1)+""+(choice+2));
number=sc.nextInt();
System.out.println("select the color from red,blue,green,yellow");
System.out.println("Enter 1 for RED 2 for BLUE 3 for GREEN 4 for YELLOW");
color=sc.nextInt();
break;
}
//start value of number is 0 and color is 1
switch((number+1)*color)
{
case 1: System.out.println("Going to be a great for you!");
break;
case 2:System.out.println("You will hear good news today!");
break;
case 3:System.out.println("You will make a new friend today");
break;
case 4:System.out.println("Today will not be a good day for you");
break;
case 5:System.out.println("You'll hear from an old friend");
break;
}
}
}