I am a beginner trying to program a train booking system which has 8 seats and requires the user to input various letters in order to execute a method. I am struggling to create a method through a private static void which when the user enters ‘E’ It shows all the empty seats through an array.
Here is the code that I have currently done so far:
package trainbookingsystem;
import java.util.Scanner;
public class Trainbookingsystem {
static final int NUMBER_OF_ROOMS = 8;
public static void main(String[] args) {
int [] Train = new int [NUMBER_OF_ROOMS];
//Display an welcome and introduction to program
//repeat
Scanner in = new Scanner(System.in);
char choice;
do
{
//display a menu
displayMenu();
//read a choice
System.out.println("--------------------------------------------------");
System.out.println("Enter a letter to select an option or (Q) to exit");
System.out.println("--------------------------------------------------");
choice = in.next().toUpperCase().charAt(0);
//process that choice
switch(choice)
{
case 'Q' :System.out.println("");
break;
case 'E' : System.out.println("You chose empty room");
showEmptySeats(Train);
break;
default: System.out.println("You enetered an invalid choice");
}
//until the user presses 'Q', while choice is not 'Q'
} while (choice != 'Q');
//Exit anf Farewell
System.out.println("Thank you for using our train booking system!");
}
private static void displayMenu() {
System.out.println("|Welcome to the Train booking system|");
System.out.println("*Use the following guide to naviagte through the program*");
System.out.println("---------------------------------------------------------");
System.out.println("| A |Add customer to seat");
System.out.println("| V |View all seats");
System.out.println("| E |Display Empty seats");
System.out.println("| D |Delete customer from seat");
System.out.println("| F |Find the seat for a given customers name");
System.out.println("| S |Store program data in to file");
System.out.println("| L |Load program data in to file");
System.out.println("| O | View seats Ordered alphabetically by name");
}
private static void showEmptySeats(int[] someArray ) {
//Go through train seats array
// if a seat is empty
int a = someArray[4];
//dsiplay it
}
}