public double getTeckitPrice(FlightSeatClass fbb) { bool isInOccasionDate = SystemHandler.IsInOccasions(DepartureDate); double price = baseFlightFare; if (fbb == FlightSeatClass.First) { price += 100; if (isInOccasionDate) { return(price - price * 10 / 100.0); } return(price); } if (fbb == FlightSeatClass.Buisness) { price += 50; if (isInOccasionDate) { return(price - price * 10 / 100.0); } return(price); } if (isInOccasionDate) { return(price - price * 10 / 100.0); } return(price); }
public int getNumOfBookedSeats(FlightSeatClass fst) { if (fst == FlightSeatClass.Buisness) { return(bookedBuisnessClass); } if (fst == FlightSeatClass.Economy) { return(bookedEconomyClass); } return(bookedFirstClass); }
public static bool viewMatchedFlight(string origin, string dest, FlightSeatClass seat, FlightType type, DateTime dept, DateTime ret) { int counter = 1; List <Object> allFlight = FileHandler.GetAllObj(ObjectChoices.Flight); foreach (Object obj in allFlight) { Flight me = (Flight)obj; if (me.FlightState == FlightSatus.Scheduled && me.OriginCity.Equals(origin, StringComparison.OrdinalIgnoreCase) && me.DestinationCity.Equals(dest, StringComparison.OrdinalIgnoreCase) && me.DepartureDate == dept && me.Type == type) { if (type == FlightType.Return && me.ReturnDate != ret) { continue; } if (seat == FlightSeatClass.Buisness && me.BuisnessClassSeat == me.getNumOfBookedSeats(seat)) { continue; } if (seat == FlightSeatClass.First && me.FirstClassSeat == me.getNumOfBookedSeats(seat)) { continue; } if (seat == FlightSeatClass.Economy && me.EconomyClassSeat == me.getNumOfBookedSeats(seat)) { continue; } Console.WriteLine("#" + counter + " : "); Console.WriteLine(me); Console.WriteLine(); counter++; } } if (counter == 1) { Console.WriteLine("No matched flights"); return(false); } return(true); }
public List <Eticket> getFlightBookings(FlightSeatClass seat) { List <Eticket> et = new List <Eticket>(); foreach (Eticket item in flightBookings) { if (item.Code[0] == 'E' && seat == FlightSeatClass.Economy) { et.Add(item); } if (item.Code[0] == 'F' && seat == FlightSeatClass.First) { et.Add(item); } if (item.Code[0] == 'B' && seat == FlightSeatClass.Buisness) { et.Add(item); } } return(et); }
public bool MakeFlightBooking(int flightNumber, FlightSeatClass seat) { Flight BookIn = (Flight)FileHandler.Find(ObjectChoices.Flight, flightNumber.ToString()); if (BookIn == null) { return(false); //write response } if (credit.getBalance() < BookIn.getTeckitPrice(seat)) { return(false); // } Eticket et = BookIn.BookSeat(this, seat); if (et == null) { return(false); // } credit.Withdraw(BookIn.getTeckitPrice(seat)); BookingList.Add(et); FileHandler.Add(ObjectChoices.Flight, BookIn); return(true); }
public static void ViewFlightBookings(int flightNumber, FlightSeatClass seat) { try { Flight flight = (Flight)FileHandler.Find(ObjectChoices.Flight, flightNumber.ToString()); List <Eticket> list = flight.getFlightBookings(seat); int counter = 0; foreach (Eticket et in list) { Console.WriteLine("Booking #" + (++counter) + " : "); Console.WriteLine(et); Console.WriteLine(); } if (counter == 0) { Console.WriteLine("no bookings"); } } catch (NullReferenceException e) { Console.WriteLine("Flight not Found"); } }
public Eticket BookSeat(Passenger pass, FlightSeatClass type) { if (DateTime.Now > departueDate) { FlightState = FlightSatus.Arrived; } if (FlightState == FlightSatus.Arrived || FlightState == FlightSatus.Canclled) { return(null); } char tp = ' '; if (type == FlightSeatClass.First && bookedFirstClass < availSeatFirstClass) { tp = 'F'; bookedFirstClass++; } else if (type == FlightSeatClass.Economy && bookedEconomyClass < availSeatEconomyClass) { tp = 'E'; bookedEconomyClass++; } else if (type == FlightSeatClass.Buisness && bookedBuisnessClass < availSeatBuisnessClass) { tp = 'B'; bookedBuisnessClass++; } else { return(null); } Eticket et = new Eticket(pass.Name, pass.PassportNumber, flightNumber, getTeckitPrice(type), tp); flightBookings.Add(et); //Console.WriteLine("Congrats ! Succesfull booking.."); return(et); }
public void interact() { while (true) { Console.WriteLine(PassengerList); string choice = Console.ReadLine(); switch (choice) { case "1": bool yes = false; string origin, dest, travelClass, flightType; DateTime dept = new DateTime(); DateTime ret = new DateTime(); string day, month, year; FlightType p1 = FlightType.OneWay; FlightSeatClass p2 = FlightSeatClass.Economy; Console.WriteLine("Please, enter the origin city : "); origin = Console.ReadLine(); Console.WriteLine("Please, enter the destination city : "); dest = Console.ReadLine(); Console.WriteLine("Please, enter the travel class : \n" + "(1 : First class) (2 : Economy class) (3 : Buinsness class)"); travelClass = Console.ReadLine(); if (!(SystemHandler.checkInt(travelClass) && int.Parse(travelClass) >= 1 && int.Parse(travelClass) <= 3)) { goto label; } Console.WriteLine("Please, enter the flight type : \n" + "(1 : one way) (2 : return)"); flightType = Console.ReadLine(); Console.WriteLine("Please, enter the departur date : "); Console.WriteLine("day : "); day = Console.ReadLine(); Console.WriteLine("month : "); month = Console.ReadLine(); Console.WriteLine("year : "); year = Console.ReadLine(); if (SystemHandler.checkDate(day, month, year)) { dept = new DateTime(int.Parse(year), int.Parse(month), int.Parse(day)); } else { goto label; } if (flightType == "2") { Console.WriteLine("Please, enter the return date : "); Console.WriteLine("day : "); day = Console.ReadLine(); Console.WriteLine("month : "); month = Console.ReadLine(); Console.WriteLine("year : "); year = Console.ReadLine(); if (SystemHandler.checkDate(day, month, year)) { ret = new DateTime(int.Parse(year), int.Parse(month), int.Parse(day)); if (ret <= dept) { goto label; } } else { goto label; } } if (flightType == "1") { p1 = FlightType.OneWay; } else if (flightType == "2") { p1 = FlightType.Return; } else { goto label; } if (travelClass == "1") { p2 = FlightSeatClass.First; } else if (travelClass == "2") { p2 = FlightSeatClass.Economy; } else if (travelClass == "3") { p2 = FlightSeatClass.Buisness; } else { goto label; } if (SystemHandler.viewMatchedFlight(origin, dest, p2, p1, dept, ret)) { yes = true; } label: if (yes) { Console.WriteLine("Please, enter the number of the flight you want to book in : "); string number = Console.ReadLine(); if (!passenger.MakeFlightBooking(int.Parse(number), p2)) { Console.WriteLine("wrong choice for flight number or you don't have enough money to book"); } } break; case "2": passenger.ViewPassengerBookings(); Console.WriteLine("Please, choose the teckit code you want to cancel"); string code = Console.ReadLine(); if (!passenger.CancelFlightBooking(code)) { Console.WriteLine("No teckit with such a code"); } break; case "3": passenger.ViewPassengerBookings(); break; case "4": FileHandler.Add(ObjectChoices.Passenger, passenger); return; default: break; } } }