 import java.util.Scanner;
 import java.util.Date;
 public class train
 {
private static int[] seats = new int[14];
public static void main(String args[])
{
System.out.println("Welcome to the train reservation system!");
System.out.println("Happy journey!");
System.out.println();
for (int i = 0; i < 14; i++) {
seats[i] = 0;
}
Scanner s = new Scanner(System.in);
int choice = 1;
System.out.print("Please enter your choice\n1.window seat in general compartment and AC tier(2,3) \n2.Aisle seat in general compartment and AC tier(2,3)\n0.Exit.\n");
choice = s.nextInt();
while (choice != 0) {
int seatnumber = 0;
if (choice == 1) {
seatnumber = bookWindow();
if (seatnumber == -1) {
seatnumber = bookAisle();
if (seatnumber != -1) {
System.out.println("Sorry, we were not able to book a window seat. Butdo have an aisle seat.");
printBoardingPass(seatnumber);
}
}
else {
System.out.println("You are lucky, we have a window seat available!");
printBoardingPass(seatnumber);
}
}
else if (choice == 2) {
seatnumber = bookAisle();
if (seatnumber == -1) 
{
seatnumber = bookWindow();
if (seatnumber != -1) 
{
System.out.println("Sorry, we were not able to book an aisle seat. Butdo have a window seat.");
printBoardingPass(seatnumber);
}
}
else {
System.out.println("You are lucky, we have an aisle seat available!");
printBoardingPass(seatnumber);
}
}
else {
System.out.println("Invalid choice made. Please try again!");
choice = 0;
}
if (seatnumber == -1) {
System.out.println("We are sorry, there are no window or aisle seats available.");
System.out.println();
}
System.out.print("Please enter your choice\n1.window seat in general compartment and AC tier(2,3) \n2.Aisle seat in general compartment and AC tier(2,3)\n0.Exit.\n");
choice = s.nextInt();
}

}
private static int bookWindow() 
{
for (int i = 0; i < 4; i++) 
{
if (seats[i] == 0)
 {
seats[i] = 1;
return i + 1;
}
}
return -1;
}
private static int bookAisle()
 {
for (int i = 4; i < 14; i++)
 {
if (seats[i] == 0)
 {
seats[i] = 1;
return i + 1;
}
}
return -1;
}
public static void printBoardingPass(int seatnumber) {
Date timenow = new Date();
System.out.println();
System.out.println("Date: " + timenow.toString());
System.out.println("Boarding pass for seat number: " + seatnumber);
System.out.println("This ticket is refundable with in a period of time ");
System.out.println("Be aware, keep clean! ");
System.out.println();
}
}