Exemplo n.º 1
0
 public GarageHandler(int capacity)
 {
     garage = new Garage <Vehicle>(capacity);
     ui     = new UI();
     count  = TotalVehicles();
 }
Exemplo n.º 2
0
        private void DisplayParkedVehicles()
        {
            int parkedAirplane   = 0;
            int parkedMotorcycle = 0;
            int parkedCar        = 0;
            int parkedBus        = 0;
            int parkedBoat       = 0;
            var vList            = garageHandler.garage.Vehicles;
            var vehicles         = new Garage <Vehicle>(Capacity);

            foreach (Vehicle item in vList)
            {
                if (item == null)
                {
                    ui.Print($"Parking place is empty");
                }
                else
                {
                    string baseString = $"{item.GetType().Name} has registration number {item.RegNo}, color {item.Color}, and {item.NumOfWheels} wheels";

                    if (item is Airplane)
                    {
                        var plane = item as Airplane;
                        parkedAirplane++;
                        ui.Print($"{baseString} {plane.NumOfEngines} engines");
                    }
                    if (item is Car)
                    {
                        var car = item as Car;
                        parkedCar++;
                        ui.Print($"{baseString} needs {car.FuelType}");
                    }

                    if (item is Motorcycle)
                    {
                        var motorcycle = item as Motorcycle;
                        parkedMotorcycle++;
                        ui.Print($"{baseString} has {motorcycle.CylinderVolume} cm cylinder");
                    }
                    if (item is Boat)
                    {
                        var boat = item as Boat;
                        parkedBoat++;
                        ui.Print($"{baseString} is {boat.LengthOfBoat} long");
                    }
                    if (item is Bus)
                    {
                        var bus = item as Bus;
                        parkedBus++;
                        ui.Print($"{baseString} has {bus.NumberOfSeats} seats");
                    }
                }
            }
            garageHandler.TotalParkedVehicles(parkedAirplane, "Airplane");
            garageHandler.TotalParkedVehicles(parkedMotorcycle, "Motorcycle");
            garageHandler.TotalParkedVehicles(parkedCar, "Car");
            garageHandler.TotalParkedVehicles(parkedBus, "Bus");
            garageHandler.TotalParkedVehicles(parkedBoat, "Boat");
            int garageVehicles = parkedAirplane + parkedCar + parkedMotorcycle + parkedBus + parkedBoat;

            ui.Print($"Total vehicles in the garage: {garageVehicles}");
            int availableParkingSpot = garageHandler.garage.Capacity - garageHandler.garage.Count;

            ui.Print($"Available parking spot: {availableParkingSpot}");
        }