public Automobile GiveFreeCar()
        {
            Randomizer rnd = Randomizer.GetInstance();
            int random = rnd.GetValue(0, numberOfCars);
            int i = random;
            int limit = random - 1;
            if (limit < 0)
                limit = numberOfCars - 1;

            for (; ; i++)
            {
                if (i == cars.Length)
                    i = 0;

                if(cars[i] == null)
                {
                    cars[i] = new Automobile(i);
                    return cars[i];
                }
                if (!cars[i].IsParked() && !cars[i].Conscificated)
                    return cars[i];
                if (i == limit)
                    break;
            }

            return null;
        }
Example #2
0
 private ParkingReservation FindReservation(Zone zone, Automobile car)
 {
     foreach(ParkingReservation reservation in reservations)
     {
         if (reservation.Zone == zone && reservation.Car == car)
             return reservation;
     }
     return null;
 }
Example #3
0
 public void Conscificate(Zone zone, Automobile car, int fine)
 {
     monitor.Check();
     GlobalParameters globalParameters = GlobalParameters.GetInstance();
     int currentTime = globalParameters.Timer;
     ParkingReservation reservation = FindReservation(zone, car);
     car.Conscificate(fine);
     zone.Fines = fine;
     zone.Remove(car);
     zone.ConscificatedCars++;
     reservations.Remove(reservation);
     ViewerCache viewerCache = ViewerCache.GetInstance();
     viewerCache.Add(currentTime.ToString() + ": Automobil " + car.ID.ToString() + " u zoni " + zone.ID.ToString() 
         + " je conscificiran a vlasniku je data kazna u vrijednosti od " + fine.ToString() + " HRK");
     monitor.Release();
 }
Example #4
0
        public bool ReservePlaceInZone(Automobile car, Zone zone)
        {
            monitor.Check();

            bool returnValue;
            if (!open)
            {
                returnValue = false;
            }
            else if (zone.IsFull())
            {
                GlobalParameters globalParameters = GlobalParameters.GetInstance();
                ViewerCache viewerCache = ViewerCache.GetInstance();
                zone.LostClients++;
                viewerCache.Add(globalParameters.Timer.ToString() + ": Automobilu " + car.ID + " odbijeno parkiranje u zoni " + zone.ID.ToString() + " jer nije bilo prostora");
                returnValue = false;
            }
            else
            {
                GlobalParameters globalParameters = GlobalParameters.GetInstance();
                int currentTime = globalParameters.Timer;
                ParkingReservation newReservation = new ParkingReservation(car, zone, currentTime);
                reservations.Add(newReservation);
                zone.Add(car);
                int parkingBill = (zones.Length + 1 - zone.ID) * globalParameters.ArgumentHolder.UnitPrice;
                car.AddParkingBill(parkingBill);
                zone.Profit = parkingBill;
                ViewerCache viewerCache = ViewerCache.GetInstance();
                viewerCache.Add(currentTime.ToString() + ": Naplaćeno parkiranje u zoni " + zone.ID.ToString() + " automobilu " + car.ID.ToString() + " u iznosu od " + parkingBill.ToString() + " HRK");
                returnValue = true;
            }

            monitor.Release();
            return returnValue;
        }
Example #5
0
 public void Remove(Automobile car)
 {
     cars.Remove(car);
 }
Example #6
0
 public void Add(Automobile car)
 {
     cars.Add(car);
 }