Platinum Partner
web dev,c#

Parking Lot - Simplistic Design C#

Parking Lot Design Implementation in C#.

    public class ParkingLot
    {
        List _parkingSpots;

        public ParkingLot()
        {
            _parkingSpots = new List();
            // 10 parking spots; 2 free; 6 Regular Paid; 2 Handicapped Free

            //2 free
            for (int i = 0; i  p.IsFree == true && p.IsAvailable);
        }

        public ParkingSpot FindPaidSpot()
        {
            return this._parkingSpots.Find(p => p.IsFree == false && p.IsAvailable);
        }

        public int GetAvailableSpotsCount()
        {
            return this._parkingSpots.Count(p => p.IsAvailable);
        }

        public int GetTotalSpots()
        {
            return this._parkingSpots.Count;
        }
    }

    public class ParkingSpot
    {
        public bool IsAvailable { get; set; }
        public bool IsFree { get; set; }
        public IVehicle ParkedVehicle { get; set; }
        public ParkingMeter Meter { get; set; }

        public void Park(IVehicle vehicle)
        {
            if (this.ParkedVehicle == null)
            {
                this.ParkedVehicle = vehicle;
                this.IsAvailable = false;
            }
            else
            {
                throw new Exception("Parking Spot is Taken. Cannot Park here!");
            }
        }

        public ParkingSpot()
        {
            this.IsAvailable = true;
            this.IsFree = true;
        }

        public ParkingSpot(bool isFree)
        {
            this.IsAvailable = true;
            this.IsFree = isFree;
            if (!this.IsFree)
            {
                this.Meter = new ParkingMeter();
            }
        }
    }

    public class HandicappedParkingSpot : ParkingSpot
    {

    }

    public class ParkingMeter
    {
        public DateTime EndTime { get; set; }
        public int MinutesRemaining
        {
            get
            {
                if (DateTime.Now >= EndTime)
                    return 0;
                else
                    return (EndTime - DateTime.Now).Minutes;
            }
        }

        public int ParkingIntervalMins
        {
            get
            {
                return 1;
            }
        }

        public void Pay(int quarters)
        {
            EndTime = DateTime.Now.AddMinutes(quarters * ParkingIntervalMins);
        }

    }


    public interface IVehicle
    {
        string Make { get; set; }
        string Model { get; set; }
        void Drive();
    }

    public class Car : IVehicle
    {
        public string Make
        {
            get;
            set;
        }

        public string Model
        {
            get;
            set;
        }

        public void Drive()
        {
        }

        public void Park()
        {
        }

    }

    public class Truck : IVehicle
    {
        public string Make
        {
            get;
            set;
        }

        public string Model
        {
            get;
            set;
        }

        public void Drive()
        {
        }

        public void Park()
        {
        }
    }
{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}