//SECTION: 02
//GROUP: TOP GUN

//FERRY TICKETING MANAGEMENT SYSTEM

import java.io.*;
import java.util.Scanner;
import java.util.*;

public class TestTicket //main
{
  public static void main(String args[])
  {
  Scanner menu1 = new Scanner(System.in);
  Scanner menu2 = new Scanner(System.in);
  ArrayList<Passenger> pList = new ArrayList<Passenger>();
  
  //Declare ferry for Langkawi Ferry Line and Orkid Malaysia
  Ferry f1 = new Ferry("Langkawi Ferry Line","Maimunah Binti Samsuddin","RJ10845");
  Ferry f2 = new Ferry("Ferry Line Venture","Rosely Bin Abu","UV70615");

  //run loop until menu 5 is not pressed
    int choose;
      do{
         System.out.println("\n\n********** TOP GUN FERRY TICKET AGENCY ************");
  	     System.out.println("1. Book Ticket");
  	     System.out.println("2. Display ticket available");
  	     System.out.println("3. Display Ferry info");
  	     System.out.println("4. Display Payment");
  	     System.out.println("5. Exit\n");

  	     System.out.print("Please enter your choice (1-5) : ");
  	     choose = menu1.nextInt();

  		 switch(choose)
  		 {
  			case 1:       //menu1 to book the bus
  			   Passenger p1;
  			   //Passenger p2;
  			   Scanner menu = new Scanner(System.in);
  			   String d;
  			   String n, cid;
  			   int p;
  			   int c;


  			   System.out.print("\nEnter passenger ID: ");
  			   d = menu.next();

			   System.out.print("Enter passenger Name: ");
			   n = menu.next();

			   System.out.print("Enter passenger phoneNum: ");
			   p = menu.nextInt();

			   do{
                           System.out.println("Enter your category(Adults - 1/ Kids - 2): "); //this is inheritance for class Ticket
			   //choose bwtween adults or kids
                           c = menu.nextInt();                                                     

			   if(c == 2){
					cid = "Kids";
                                        break;
		   	   }
                           else if(c == 1){
				   	cid = "Adults";
                                        break;
			   }
                           else{
                               System.out.println("ERROR!!! Invalid data\n");
                           }
                           }while(true);

			   p1 = new Passenger(d,n,p,cid);
			   int choice;
			   int seat1 = f1.getAvailableSeat();
			   int seat2 = f2.getAvailableSeat();

			   do{
			   System.out.println("\nWhich ferry you want to book?");
			   System.out.println("1. Langkawi Ferry Line - RM50.00 (Available seat " + seat1 + ")" );
			   System.out.println("2. Ferry Line Venture - RM48.00 (Available seat " + seat2 + ")" );
			   System.out.println("Your choice: ");
			   choice = menu2.nextInt();
			   }while((choice == 1 && seat1 == 0) || (choice == 2 && seat2 == 0));
			   boolean status = true;

			   switch (choice){

			   case 1:  // still in menu 1, to choose the type of bus between Langkawi Ferry Line and Ferry Line Venture

			   	double insurance_Rate = 0.05, Kids_disRate = 0.4;
			   	double price = 50.0;
			   	String compName = "Langkawi Ferry Line";

			  	if(cid == "Kids"){
					String cate = "Kids";
					Kids n1 = new Kids(Kids_disRate,50.0,p1.getName(),compName,"MY" + f1.getSeatNum(),cate,p1.getPhoneNum());
					System.out.println("\nYour original ticket price is: RM" + n1.getPrice());
			  		System.out.println("Your total ticket price is: RM" + n1.calculatePrice());
			  		f1.assign(n1);
					for(int i = 0; i<pList.size(); i++){

						if (d.equals(pList.get(i).getID())){

							p1.book(n1);
							status = false;
							break;
					}}

				    if(pList.size() == 0 || status){

					   p1.book(n1);
					   pList.add(p1);
				    }

				}
				else{
					String cate = "Adults";
					Adults n1 = new Adults(insurance_Rate,50.0,p1.getName(),compName,"MY" + f1.getSeatNum(),cate,p1.getPhoneNum());
					System.out.println("\nYour original ticket price is: RM" + n1.getPrice());
			  		System.out.println("Your total ticket price is: RM" + n1.calculatePrice());
			  		f1.assign(n1);
					for(int i = 0; i<pList.size(); i++){

						if (d.equals(pList.get(i).getID())){

							p1.book(n1);
							status = false;
							break;
					}}

				    if(pList.size() == 0 || status){

					   p1.book(n1);
					   pList.add(p1);

				    }
				}
			  	break;

			   case 2:

				double insurance_Rate2 = 0.08, Kids_disRate2 = 0.3;
			   	double price2 = 48.0;
			   	String compName2 = "Ferry Line Venture";

			  	if(cid == "Kids"){
					String cate = "Kids";
					Kids n1 = new Kids(Kids_disRate2,50.0,p1.getName(),compName2,"ORM" + f2.getSeatNum(),cate,p1.getPhoneNum());
					System.out.println("\nYour original ticket price is: RM" + n1.getPrice());
			  		System.out.println("Your total ticket price is: RM" + n1.calculatePrice());
			  		f2.assign(n1);
					for(int i = 0; i<pList.size(); i++){

						if (d.equals(pList.get(i).getID())){

							p1.book(n1);
							status = false;
							break;
					}}

				    if(pList.size() == 0 || status){

					   p1.book(n1);
					   pList.add(p1);
				    }
				}
				else{
					String cate = "Adults";
					Adults n1 = new Adults(insurance_Rate2,50.0,p1.getName(),compName2,"ORM" + f2.getSeatNum(),cate,p1.getPhoneNum());
					System.out.println("\nYour original ticket price is: RM" + n1.getPrice());
			  		System.out.println("Your total ticket price is: RM" + n1.calculatePrice());
			  		f2.assign(n1);
					for(int i = 0; i<pList.size(); i++){

						if (d.equals(pList.get(i).getID())){

							pList.get(i).book(n1);
							status = false;
							break;
					}}

				    if(pList.size() == 0 || status){

					   p1.book(n1);
					   pList.add(p1);
				    }
				}
			  	break;
			   }
			   break;

        	case 2:
                
                System.out.println("\nAvailable ticket for: ");
                System.out.println("\nLangkawi Ferry Line: " + f1.getAvailableSeat() + " tickets still available!");
                System.out.println("\nFerry Line Venture: " + f2.getAvailableSeat() + " tickets still available!");

                break;

          	case 3:  //in menu 3, display passenger and ferry info

                System.out.println("\n");
                f1.displayInfo();
                f1.DisplayPassengerList();
                System.out.println("\n");
                f2.displayInfo();
                f2.DisplayPassengerList();
                break;

          	case 4:  //in menu 4, show the info for the ticket

          		if(pList.size() == 0){
					System.out.println("Sorry, no tickets been bought yet!");
				}
				else

					for(int i = 0; i<pList.size(); i++){

						System.out.println("\nID: " + pList.get(i).getID());
						System.out.println("\tName: " + pList.get(i).getName());
						System.out.println("\tPhone number: " + pList.get(i).getPhoneNum());
						System.out.println("\tCategory: " + pList.get(i).getCategoryId());

						pList.get(i).displayInfoTicket();
				}
				break;

          	case 5:
                System.out.println("\n\t\t\t*----------------------*");
                System.out.println("\t\t\t\tThank You..");
                System.out.println("\t\t\tWe are glad to help you!!!");
                System.out.println("\t\t\t\tTOP GUN");
                System.out.println("\t\t\t*----------------------*");
                break;
  	      }
  	    System.out.println("\nReturning to main menu...");
  	 	try {
		Thread.sleep(2500);
        } catch (Exception e) {
                    System.out.println("INVALID DATA !!!");
        }

  	  }while(choose != 5);
    }
}