Exemplo n.º 1
0
        /// <summary>
        /// Park vehicle and turn on meter.
        /// </summary>
        public void AddVehicle()
        {
            if (Settings.capacity > Parking.GetInstance().vehicles.Count)
            {
                this.ReadInfo(out int type, out double balance, out string licenseNumber);
                Vehicle v = this.CreateVehicle(type, balance, licenseNumber);
                v.IsParked = true;

                if (!VehicleViewer.IsParked(v.Id))
                {
                    Parking.GetInstance().vehicles.Add(v);
                    this.tm    = new TimerCallback(this.GetPaid);
                    this.timer = new Timer(this.tm, v, 0, Settings.period);
                    Console.WriteLine("Your vehicle is parked.");
                }
                else
                {
                    Console.WriteLine("Your vehicle has already parked.");
                }
            }
            else
            {
                Console.WriteLine("Sorry, the ParkingLot is full.");
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine(Menu);
                string choise = ReadInput();
                if (int.TryParse(choise, out int num) && Enumerable.Range(1, 9).Contains(num))
                {
                    switch (num)
                    {
                    case 1:
                        Console.WriteLine($"The balance of ParkingLot is {Parking.GetInstance().Balance}");
                        break;

                    case 2:
                        Console.WriteLine($"The amount of money earned for last minute is { TransactionsViewer.ShowLastMinuteIncome()}");
                        break;

                    case 3:
                        Console.WriteLine($"There are {Settings.capacity - Parking.GetInstance().vehicles.Count} spare places at the parking.");
                        break;

                    case 4:
                        TransactionsViewer.ViewLastMinuteTransactions();
                        break;

                    case 5:
                        TransactionsLogger.ShowAllTranactions();
                        break;

                    case 6:
                        VehicleViewer.ShowParkedVehicle();
                        break;

                    case 7:
                        new VehicleCreator().AddVehicle();
                        TransactionsLogger.LogTransactions();
                        break;

                    case 8:
                        VehicleRemover.TakeVehicle();
                        break;

                    case 9:
                        VehicleAccount.FundAccount(VehicleViewer.FindVehicle(VehicleViewer.ReadLicenseNumber()));
                        break;
                    }
                }
                else
                {
                    Console.WriteLine("Incorrect input. Try again!");
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Check whether the vehicle is parked.
        /// </summary>
        public static void TakeVehicle()
        {
            var id = VehicleViewer.ReadLicenseNumber();

            if (VehicleViewer.IsParked(id))
            {
                var v = VehicleViewer.FindVehicle(id);
                check : if (v.Balance < 0)
                {
                    Console.WriteLine($"You have a debt for parking in amount of {v.Balance}. Please fund your account.");
                    VehicleAccount.FundAccount(v);
                    goto check;
                }

                v.IsParked = false;
                Parking.GetInstance().vehicles.Remove(v);
                Console.WriteLine("Taking vehicle is successful.");
            }
            else
            {
                Console.WriteLine($"There is no vehicle with license number {id}");
            }
        }