示例#1
0
 // executes the option according to chosen state
 public void ExecuteOption(EzySystem ezySystem)
 {
     if (_state == 0)        // go to previous menu
     {
         return;
     }
     else if (_state == 1)   // add bus stop (prompt for necessary details then execute action)
     {
         AddBusStop(ezySystem);
     }
     else if (_state == 2)   // add bus service
     {
         AddBus(ezySystem);
     }
     else if (_state == 3)   // add route
     {
         AddRoute(ezySystem);
     }
     else if (_state == 4)   // display bus stops
     {
         DisplayBusStops(ezySystem);
     }
     else if (_state == 5)   // display bus services
     {
         DisplayBusServices(ezySystem);
     }
     else if (_state == 6)    // display bus service route
     {
         DisplayBusServiceRoute(ezySystem);
     }
 }
示例#2
0
        // lets a user choose an option from the given set of options
        public void ChooseOption(EzySystem ezySystem)
        {
            Console.Clear();
            Console.WriteLine("SIMULATION MENU- Local time is now: " + ezySystem.GetTime() );
            Console.WriteLine("\n0) Return to Previous Menu");
            Console.WriteLine("1) Start a passenger trip");
            Console.WriteLine("2) Go to next available event");

            Console.Write("\nPlease enter option number: ");
            _state = Int32.Parse(Console.ReadLine());
        }
示例#3
0
 // Display bus services route
 private void DisplayBusServiceRoute(EzySystem ezySystem)
 {
     Console.Write("Please enter the name of the bus service that you want to view: ");
     string busName = Console.ReadLine();
     Console.WriteLine(ezySystem.GetRoute(busName));
 }
示例#4
0
 // Display bus services
 private void DisplayBusServices(EzySystem ezySystem)
 {
     Console.WriteLine(ezySystem.GetBusStringList());
 }
示例#5
0
 // Add new route to the system
 private void AddRoute(EzySystem ezySystem)
 {
     Console.Write("Please enter the name of the bus that you want to modify: ");
     string busName = Console.ReadLine();
     Console.Write("Please enter the initial bus stop: ");
     string initialBusStop = Console.ReadLine();
     Console.Write("Please enter the terminal bus stop: ");
     string terminalBusStop = Console.ReadLine();
     Console.Write("Please enter the travel time from initial bus stop to terminal bus stop : ");
     string trv = Console.ReadLine();
     int traveltime = System.Convert.ToInt32(trv, 10);
     ezySystem.CreateRoute(busName, initialBusStop, terminalBusStop, traveltime);
     
 }
示例#6
0
 // Add new bus to the system
 private void AddBus(EzySystem ezySystem)
 {
     Console.Write("Please enter the name of the bus: ");
     string name = Console.ReadLine();
     Console.Write("Please enter the frequency of the bus: ");
     string frequency = Console.ReadLine();
     ezySystem.CreateBus(name, System.Convert.ToInt32(frequency));
     
 }
示例#7
0
 // Add new busstop to the system
 private void AddBusStop(EzySystem ezySystem)
 {
     Console.Write("Please enter the name of the bus stop: ");
     string name = Console.ReadLine();
     ezySystem.CreateBusStop(name);
 }
示例#8
0
        // display all passengers which were able to hop on successfully, send SMS, issue ticket and deduct from account
        private void UserHopOn(EzySystem ezySystem)
        {
            // check expiry ticket
            List<string> temp = ezySystem.GetWhoHasHopOn();
            if (temp.Count == 0) return;

            SimulationBox.Text += ("The following users have sucessfully hopped on: "+ "\n");
            for (int i = 0; i < temp.Count; i++)
            {
                SimulationBox.Text += temp.ElementAt(i);
            }


        }
示例#9
0
        private void DisplayAllBusArrivals(EzySystem ezySystem)
        {
            // for each bus stop, check whether the bus queue has a bus which indicates that a bus has arrived
            for (int i = 0; i < ezySystem.GetBusStopList().GetCount(); i++)
            {
                // if there is at least one bus, display all bus arrivals
                if (ezySystem.GetBusStopList().At(i).GetBusQueueCount() > 0)
                {
                    for (int j = 0; j < ezySystem.GetBusStopList().At(i).GetBusQueueCount(); j++)
                    {
                        string busname = ezySystem.GetBusStopList().At(i).GetBusQueue().ElementAt(j), busstopname = ezySystem.GetBusStopList().At(i).GetName();

                        if (!ezySystem.BusNameIsInBusInterruptList1(busname, busstopname) && !ezySystem.BusStopIsInterrupted(busstopname))
                            DisplayBusArrival(ezySystem.GetBusStopList().At(i).GetName(), ezySystem.GetBusStopList().At(i).GetBusQueue().ElementAt(j));
                    }
                }
            }
        }
示例#10
0
        // executes the option according to chosen state
        public void ExecuteOption(EzySystem ezySystem)
        {
            if (_state == 0)        // go to previous menu
            {
                return;
            }
            else if (_state == 1)   // add a trip
            {
                Console.WriteLine("\nPlease enter the following details.");
                Console.Write("1) Passenger mobile number: ");
                string mobileNum = Console.ReadLine();
                Console.Write("2) Bus Stop to queue into: ");
                string stop = Console.ReadLine();
                Console.Write("2) Bus Service to hop into: ");
                string bus = Console.ReadLine();
                ezySystem.EnqueueUserToBusStop(mobileNum, stop, bus);
            }
            else if (_state == 2)   // go to next available event (when bus arrives to a bus stop)
            {
                // increase time first
                // continue increasing time until the next event is reached (i.e. bus arrives a bus stop)

                while (!ezySystem.GetHasEvent())
                {
                    ezySystem.IncreaseTime();
                }
                Console.Clear();
                Console.WriteLine("SIMULATION MENU- Local time is now: " + ezySystem.GetTime());
                Console.WriteLine("\n0) Return to Previous Menu");
                Console.WriteLine("1) Start a passenger trip");
                Console.WriteLine("2) Go to next available event");

                Console.Write("\nPlease enter option number: 2\n");
                
                // after increasing the time, check the bus stop list for buses which has arrived and display all of them
                DisplayAllBusArrivals(ezySystem);
                // Ask 'God' if any user wants to hop off

                UserAutoHopOff(ezySystem);

                UserHopOffMenu(ezySystem);
                // Process hop on logic inside the ezySystem
                // Display successful user hop ons
                UserHopOn(ezySystem);

                //while (ezySystem.GetBusArrivalList().GetCount()>0)
                //{   
                //    // displaying that bus X arrived at bus stop Y
                //    Console.WriteLine(ezySystem.GetBusArrivalList().GetFirstBusArrival().GetBusName() + " has reached bus stop " + ezySystem.GetBusArrivalList().GetFirstBusArrival().GetBusStopName());
                //    // display passengers inside the bus
                //    Console.WriteLine("Bus " + ezySystem.GetBusArrivalList().GetFirstBusArrival().GetBusName() + " has the following passengers: "); // edit later
                //    // letting simulation 'God' decide which users to hop off the bus
                    
                //    // transferring users from the bus stop queue to the bus passenger list
                //    // displaying the successful hopping on of passengers
                //    // repeat this block of code (i.e. processing of bus arrival list) until all bus arrivals are processed
                //}
                Console.Write("Press any key to continue "); Console.ReadKey();
                ezySystem.ResetHasEvent();
            }
        }
示例#11
0
        // display all passengers which were able to hop on successfully, send SMS, issue ticket and deduct from account
        private void UserHopOn(EzySystem ezySystem)
        {
            // check expiry ticket
            List<string> temp = ezySystem.GetWhoHasHopOn();
            if (temp.Count == 0) return;
            
            Console.WriteLine("The following users have sucessfully hopped on: ");
            for (int i = 0; i < temp.Count; i++)
            {
                Console.WriteLine(temp.ElementAt(i));
            }
            

        }
示例#12
0
        // menu which asks for user input for hopping off the bus
        private void UserHopOffMenu(EzySystem ezySystem)
        {
            if (ezySystem.ThereIsPassengerOnBus())
            {
                Console.Write("Do you want to hop off passengers? (Y/N) ");
                string input = Console.ReadLine();

                while (String.Equals(input, "Y") || String.Equals(input, "y"))
                {
                    Console.WriteLine("Please select a bus stop from the list above.");
                    string busStopName = Console.ReadLine();
                    Console.WriteLine("The following are the buses which arrived at the chosen bus stop. Please select one.\n");
                    // display all buses in the bus stop
                    for (int i = 0; i < ezySystem.GetBusStopList().FindBusStopWithBusStopName(busStopName).GetBusQueueCount(); i++)
                    {
                        Console.WriteLine((i + 1) + ")" + ezySystem.GetBusStopList().FindBusStopWithBusStopName(busStopName).GetBusQueue()[i]);
                    }

                    string busName = Console.ReadLine();
                    Console.WriteLine("The following are the passengers inside this particular bus. Please select who will hop off.");
                    // display all passengers inside the bus // where to get the passenger
                    for (int i = 0; i < ezySystem.GetBusList().FindBusWithBusName(busName).GetPassengerList().Count; i++)
                    {
                        Console.WriteLine((i + 1) + ")" + ezySystem.FindUserWithMobileNumber(ezySystem.GetBusList().FindBusWithBusName(busName).GetPassengerList().ElementAt(i).GetMobileNum()));
                        //Console.WriteLine((i + 1) + ")" + ezySystem.GetUserList().FindUserWithMobileNumber((ezySystem.GetBusStopList().FindBusStopWithBusStopName(busStopName).GetPassengerList()[i].GetMobileNum())).GetName());
                    }

                    string userName = Console.ReadLine();
                    // remove passenger from the bus after this line
                    ezySystem.DequeueUserFromBus(userName, busName, busStopName);

                    // ask again if another passenger wants to hop off
                    Console.Write("\nDo you want to hop off passengers? (Y/N) ");
                    input = Console.ReadLine();
                }
            }
        }
示例#13
0
 private void UserAutoHopOff(EzySystem ezySystem)
 {
     List<string> temp = ezySystem.GetWhoHasAutoHopOff();
     if (temp.Count == 0) return;
     Console.Write("The following passengers have been hopped off because they reach the last bus stop \n");
     
     for (int i = 0; i < temp.Count; i++)
     {
         Console.WriteLine(temp.ElementAt(i));
     }
     ezySystem.ClearAutoHopOffList();
 }
示例#14
0
 // displays all of the bus arrivals
 private void DisplayAllBusArrivals(EzySystem ezySystem)
 {
     // for each bus stop, check whether the bus queue has a bus which indicates that a bus has arrived
     for (int i = 0; i < ezySystem.GetBusStopList().GetCount(); i++)
     {
         // if there is at least one bus, display all bus arrivals
         if (ezySystem.GetBusStopList().At(i).GetBusQueueCount() > 0)
         {
             for (int j = 0; j < ezySystem.GetBusStopList().At(i).GetBusQueueCount(); j++)
             {
                 DisplayBusArrival(ezySystem.GetBusStopList().At(i).GetName(), ezySystem.GetBusStopList().At(i).GetBusQueue().ElementAt(j));
             }
         }
     }
 }
示例#15
0
        // executes the option according to chosen state
        public void ExecuteOption(EzySystem ezySystem)
        {
            if (_state == 0)                         // go back to previous menu
                return;

            else if (_state == 1)                    // enter user UI
            {
                UserUI newUserUI = new UserUI();
                newUserUI.Initialize(ezySystem);

                // Run the UI until exit
                while (true)
                {
                    if (newUserUI.GetState() == 0)   // mark of program exit
                        break;
                    else                             // if not exit
                    {
                        newUserUI.ChooseOption();
                        newUserUI.ExecuteOption(ezySystem);
                    }
                }

                newUserUI.Exit(ezySystem);
            }

            else if (_state == 2)                    // enter admin UI
            {
                AdminUI newAdminUI = new AdminUI();
                newAdminUI.Initialize();

                // Run the UI until exit
                while (true)
                {
                    if (newAdminUI.GetState() == 0) break;// mark of program exit
                    else                            // if not exit
                    {
                        newAdminUI.ChooseOption();
                        newAdminUI.ExecuteOption(ezySystem);
                        Console.Write("Press any key to continue.");
                        Console.ReadKey();
                    }
                }

                newAdminUI.Exit();
            }
            else if (_state == 3)                   // enter simulation UI
            {
                SimulationUI newSimulationUI = new SimulationUI();
                newSimulationUI.Initialize();

                // Run the UI until exit
                while (true)
                {
                    if (newSimulationUI.GetState() == 0) // mark of program exit
                        break;
                    else                            // if not exit
                    {
                        newSimulationUI.ChooseOption(ezySystem);
                        newSimulationUI.ExecuteOption(ezySystem);
                    }
                }

                newSimulationUI.Exit();
            }
        }