I'm trying to figure out some issue I'm having.
Basically what my issue is, is that the values that are being returned by my methods aren't right.
I have the print line statement just to be sure it's working but it always returns 1
, even when I call to another method that should return a String.
The variable current_number/image_number
is supposed to be updated every time I call to a method (If I keep calling to forward starting from 1
, I should be getting 2
, 3
, 4
etc..).
This is my code
public class Menu {
static final int MIN_NUMBER = 1;
static final int MAX_NUMBER = 8;
static int image_number = 1;
static boolean exit;
public static int forward(int current_number) {
if (current_number < MAX_NUMBER) {
current_number++;
} else if (current_number >= MAX_NUMBER) {
current_number = MIN_NUMBER;
}
return current_number;
}
public static void showMenu() {
int current_number = image_number; // global int that equals 1
while (!exit) {
Scanner input = new Scanner(System.in);
Random rand = new Random();
int randomvalue = rand.nextInt(MAX_NUMBER) + MIN_NUMBER; // used in another method
System.out.println("1. forward"); // menu with options
System.out.println("2.");
System.out.println("3.");
System.out.println("4. Exit");
System.out.println(current_number);
int choice = input.nextInt();
switch (choice) {
case 1:
forward(current_number);
break;
case 4:
exit = true;
break;
}
}
}
}