hi I am building a program but when it does a job and returns to menu it wont accept any input like the scanner was not initialised can anyone see why not it will do it once but as soon as it returns to menu it stops second set of eyes would be much appreciated
//This program will provide a menu system for inputting
//data regards 3 taxi's
import java.util.Scanner;//importing the scanner utility
class c22taxis
{
public static void menu() //This method will be called by the main method later
{
//printing of the system menu on screen to user
System.out.println("Welcome to C22 Taxis automated System");
System.out.println("");// blank line
System.out.println("Please select from a option below to continue.");
System.out.println("");// blank line
System.out.println(" 1. Enter/Change Driver Name.");
System.out.println("");// blank line
System.out.println(" 2. Enter/Change veichle booking status.");
System.out.println("");// blank line
System.out.println(" 3. Enter/Change veichle service status.");
System.out.println("");// blank line
System.out.println(" 4. List all veichle status");
System.out.println("");// blank line
System.out.println(" 5. Exit");//exit command for program
System.out.println("");
System.out.print("Please select a option: ");
}
public static void main (String[]args)
{
//initialising the scanner
Scanner input = new Scanner(System.in);
//creating/initialising the variables
String taxi1, taxi2,taxi3;
String [] name = new String[3];//name array useable upto as many names as required
String [] dest = new String [3];//array for destination again as many taxis as required
int choice = 0, preference;
int tNo = 0;
menu();//calling the method /main menu
preference = input.nextInt();
if (preference == 1)// path of input from user
{
System.out.println('\f');
// sub menu for driver change details
System.out.println(" Driver name sub Menu");
System.out.println("");
System.out.println("");
System.out.print("Please enter taxi number: ");
tNo = input.nextInt();//instruction for user to input number
//if/else relating to choice made in sub menu will then prompt user for tsxi no. and then name
//name then goes in relevant array position.
switch (tNo)
{
case 1:
System.out.print("Please enter drivers name: ");
name[0] = input.next();
break;
case 2:
System.out.print("Please enter drivers name: ");
name[1] = input.next();
break;
case 3:
System.out.print("Please enter drivers name: ");
name[2] = input.next();
break;
//the default
default:
System.out.print("invalid entry return to menu.");
break;
}
menu();
}
else if (preference == 2)
{
System.out.println('\f');
//sub menu start for taxi status
System.out.println(" Taxi status sub Menu");
System.out.println("");
System.out.println("");
System.out.print("Please enter taxi number: ");
tNo = input.nextInt();//instruction for user to input number
//if/else relating to choice made in sub menu will then prompt user for taxi status
//status will then go in relevant array position.
if (tNo == 1)
{
System.out.print("Please enter taxi1 estination(if no destination enter NONE): ");
dest[0] = input.next();
}
else if (tNo ==2)
{
System.out.print("Please enter taxi2 destination(if no destination enter NONE): ");
dest[1] = input.next();
}
else if (tNo ==3)
{
System.out.print("Please enter taxi3 destination(if no destination enter NONE): ");
dest[2] = input.next();
} //else instruction at end giving invalid input for anything other
else
System.out.println("Invalid entry please restart");
}
else
System.out.println("end program");
menu();
}
}