I'm trying to make a basic 8 ball program, and got it all working, but I want to try changing it so if people ask certain questions there is a predefined answer.
package Main;
import java.util.Random;
import java.util.Scanner;
public class eightBall {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Ask a yes or no question");
String question = input.next();
double rnd = Math.random();
int random = (int)(rnd*10);
int numberOfChoices = 5;
if(question.equalsIgnoreCase("Will i win the lottery?")){
System.out.println("The almigty 8 ball can not tell you this answer.");
}else{
switch(random % numberOfChoices){
case 0:
System.out.println("No");
break;
case 1:
System.out.println("Yes");
break;
case 2:
System.out.println("Maybe");
break;
case 3:
System.out.println("Definitely");
break;
case 4:
System.out.println("Definitely Not");
break;
}
}
}
}
I'm not really sure why my if
statement there isn't working, because if I run it and ask "Will I win the lottery?", I get something from that switch statement.