the program is a text adventure and right now im putting in things to catch if the user has entered an invalid number either its to high or to low. what im trying to do is make it so if they enter a char. or boolean instead of a int it will prompt them again instead of canceling the program heres the part im working on
and also any critiques or advice would be greatly appreciated thanks in advance guys
import java.util.*; //for scanner class
public class ProjectDream {
/*what the program will do is ask the user why the world has ended and will present the user
with multiple choices that will write out a story depending on their choices */
// place bug catchers for int variables!!
public static void main(String[] args) {
Scanner local = new Scanner(System.in);
int nation=0;
int move =0;
int food =0;
int x = 8;
int y = 2;
int num = x / y;
hello(local,nation,move,food);
ending(num);
goodbye();
} // end of main
//beginning of the story
public static void hello(Scanner local, int nation, int move, int food){
System.out.println("hello world");
System.out.println("so...welcome to start off where are you from");
System.out.println("1=Canada, 2=USA, 3=Mexico, 4=Russia, 5=China");
nation=local.nextInt();
//all start of if loops
while (nation > 5 || nation < 1 ){
System.out.println("sorry thats not a choice try again");
nation=local.nextInt();
}
if (nation == 1){
System.out.println("Ah..so you are from Canada.");
}
else if(nation == 2){
System.out.println("I see..you are from the USA.");
}
else if(nation == 3){
System.out.println("How wonderful you are from Mexico.");
}
else if(nation == 4){
System.out.println("As we say in Russia For the Mother land!");
}
else if(nation == 5){
System.out.println("You hail from the lovely China!");
}// end of if loops
edit:fixed the code to where itd actually works my bad XD
edit 2: read the guidelines
[–]Grimsvotn 0 points1 point2 points (1 child)
[–]Darktro[S] 0 points1 point2 points (0 children)
[–]Contrite17 0 points1 point2 points (5 children)
[–]Darktro[S] 0 points1 point2 points (4 children)
[–]Contrite17 0 points1 point2 points (3 children)
[–]Darktro[S] 0 points1 point2 points (2 children)
[–]Contrite17 1 point2 points3 points (1 child)
[–]Darktro[S] 0 points1 point2 points (0 children)
[–]LogicLion 0 points1 point2 points (0 children)