Beispiel #1
0
        private static void Main(string[] args)
        {
            Bus bus = new Bus();
            SeatType busSoftSeat = new SeatType {Name = "Soft"};
            SeatType busHardSeat = new SeatType {Name = "Hard"};

            bus.AddSeats(busSoftSeat, 10);
            bus.AddSeats(busHardSeat, 15);

            Train train = new Train();
            SeatType trainCommonSeat = new SeatType {Name = "Common"};
            SeatType trainLuxSeat = new SeatType {Name = "Common"};

            train.AddCoach(new Coach(trainCommonSeat, 30));
            train.AddCoach(new Coach(trainCommonSeat, 45));
            train.AddCoach(new Coach(trainLuxSeat, 10));

            Plane plane = new Plane();
            SeatType planeFirstClass = new SeatType {Name = "First"};
            SeatType planeEconomyClass = new SeatType {Name = "Economy"};
            SeatType planeBusinessClass = new SeatType {Name = "Business"};

            plane.AddSeats(planeFirstClass, 10);
            plane.AddSeats(planeEconomyClass, 15);
            plane.AddSeats(planeBusinessClass, 20);

            var flights = new List<IFlight>
            {
                new Flight(bus) {FlightNumber = "256", Departure = "Minsk", Destination = "Gomel"},
                new Flight(train) {FlightNumber = "866", Departure = "Minsk", Destination = "Moscow"},
                new Flight(plane) {FlightNumber = "AC-476", Departure = "Tokyo", Destination = "New-York City"}
            };
            flights[0].SetTicketCost(busSoftSeat, (decimal) 25.5);
            flights[0].SetTicketCost(busHardSeat, (decimal) 20.5);
            flights[0].BuyTicket(busHardSeat, 10);

            flights[1].SetTicketCost(trainCommonSeat, (decimal) 40.4);
            flights[1].SetTicketCost(trainLuxSeat, (decimal) 60.8);
            flights[1].BuyTicket(trainCommonSeat, 18);
            flights[1].BuyTicket(trainLuxSeat, 4);

            flights[2].SetTicketCost(planeFirstClass, 1500);
            flights[2].SetTicketCost(planeBusinessClass, 1100);
            flights[2].SetTicketCost(planeEconomyClass, 800);
            flights[2].BuyTicket(planeFirstClass, 10);
            flights[2].BuyTicket(planeEconomyClass, 15);
            flights[2].BuyTicket(planeBusinessClass, 20);

            InfoBoard.DrawFlightBoard(flights);
            flights.Sort();

            InfoBoard.DrawFlightBoard(flights);
            InfoBoard.DrawTicketsInfo(flights.First(x => x.FlightNumber == "256"));

            Console.ReadKey();
        }
Beispiel #2
0
 public override int GetMaxSeats(SeatType type)
 {
     return _coaches.Where(x => x.SeatType == type).Sum(x => x.SeatCount);
 }
Beispiel #3
0
 public override int GetMaxSeats(SeatType type)
 {
     return _maxSeats.ContainsKey(type) ? _maxSeats[type] : 0;
 }
Beispiel #4
0
 public void AddSeats(SeatType seatType, int count)
 {
     if (!_maxSeats.ContainsKey(seatType))
         _maxSeats.Add(seatType, count);
     else _maxSeats[seatType] += count;
 }
Beispiel #5
0
 public abstract int GetMaxSeats(SeatType type);
Beispiel #6
0
 public void SetTicketCost(SeatType seatType, decimal cost)
 {
     if (!_seatTypes.ContainsKey(seatType))
     {
         _seatTypes.Add(seatType, cost);
         _freeSeats.Add(seatType, _transport.GetMaxSeats(seatType));
     }
     else _seatTypes[seatType] = cost;
 }
Beispiel #7
0
 public decimal GetTicketCost(SeatType seatType)
 {
     return _seatTypes[seatType];
 }
Beispiel #8
0
 public int GetFreeSeats(SeatType seatType)
 {
     return _freeSeats[seatType];
 }
Beispiel #9
0
 public bool BuyTicket(SeatType seatType, int count)
 {
     if (!_freeSeats.ContainsKey(seatType) || (_freeSeats[seatType] - count < 0)) return false;
     _freeSeats[seatType] -= count;
     return true;
 }
Beispiel #10
0
 public Coach(SeatType seatType, int seatCount)
 {
     SeatType = seatType;
     SeatCount = seatCount;
 }