Exemplo n.º 1
0
        void RemoveCar()
        {
            ShowAllCarsOnParking();
            Console.WriteLine("Chose car by id");
            var id = Console.ReadLine();

            try
            {
                var car = parking.FindCarById(id);
                if (car == null)
                {
                    throw new CarIsNotFoundException($"Car with id {id} is not found.");
                }
                else
                {
                    parking.RemoveCar(car);
                }
            }
            catch (CarIsNotFoundException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (FinePresentException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Exemplo n.º 2
0
        private void RemoveCarMenuItem()
        {
            var busyPlaces = Parking.GetNumberOfBusyPlaces();

            if (busyPlaces == 0)
            {
                Console.WriteLine("There are no cars in the parking.");
            }
            else
            {
                Console.WriteLine($"To remove the car, please, enter the number of this car from 1 to {busyPlaces}:");
                var numberOfCar = GetAndValidateInputInt(1, busyPlaces);
                if (_parking.HasFine(numberOfCar))
                {
                    Console.WriteLine("The car has a fine. Would you like to top up balance (press any number key except 0) or no (press 0)?");
                    var i = GetAndValidateInputInt(0, 9);
                    if (i == 0)
                    {
                        Console.WriteLine("The car was not removed.");
                        return;
                    }
                }
                var balance = _parking.RemoveCar(numberOfCar).Result;
                Console.WriteLine($"Balance was {balance}. The car removed.");
            }
        }
Exemplo n.º 3
0
        public static void ShowMenu()
        {
            int    id, sum = 0;
            string buf;
            bool   check = false;

            while (true)
            {
                PrintMenuTemplate();
                buf = Console.ReadLine();
                Console.Clear();
                switch (buf)
                {
                case "1":
                    Car car = new Car();
                    Console.WriteLine("Please enter car type(Passenger(0),Truck(1),Bus(2),Motorcycle(3)): ");
                    while (!check)
                    {
                        try
                        {
                            car.Type = (CarTypes)Enum.Parse(typeof(CarTypes), Console.ReadLine());
                            if (int.TryParse(Convert.ToString(car.Type), out int a))
                            {
                                Console.WriteLine("Not valid car type. Car type can not contains number. Please try again.");
                            }
                            else
                            {
                                check = true;
                            }
                        }
                        catch (ArgumentException)
                        {
                            Console.WriteLine("Not valid car type. Please try again.");
                        }
                        catch (OverflowException)
                        {
                            Console.WriteLine("Not valid car type. Car type can not contains number. Please try again.");
                        }
                    }
                    check = false;

                    Console.WriteLine("Please enter car id: ");
                    while (!Int32.TryParse(Console.ReadLine(), out id))
                    {
                        Console.WriteLine("Enter valid id please: ");
                    }
                    ;
                    car.Id = id;

                    Parking.AddCar(car);
                    break;

                case "2":
                    Console.WriteLine("Please enter car id: ");
                    while (!Int32.TryParse(Console.ReadLine(), out id))
                    {
                        Console.WriteLine("Enter valid id please: ");
                    }
                    ;

                    Parking.RemoveCar(id);
                    break;

                case "3":
                    Console.WriteLine("Please enter car id: ");
                    while (!Int32.TryParse(Console.ReadLine(), out id))
                    {
                        Console.WriteLine("Enter valid id please: ");
                    }
                    ;
                    Console.WriteLine("Input sum please: ");
                    while (!Int32.TryParse(Console.ReadLine(), out sum))
                    {
                        Console.WriteLine("Enter valid sum please: ");
                    }
                    ;

                    Car c = Parking.Cars.Find(cars => cars.Id == id);
                    if (c == null)
                    {
                        Console.WriteLine("No such car at parking");
                    }
                    else
                    {
                        c.Balance += sum;
                    }

                    break;

                case "4":
                    Parking.PrintTransactions();
                    break;

                case "5":
                    Settings.LogReader();
                    break;

                case "6":
                    Console.WriteLine("Total parking balance:{0}", Parking.Balance);
                    break;

                case "7":
                    Console.WriteLine("Current parking balance:{0}", Parking.CurrentBalance);
                    break;

                case "8":
                    Console.WriteLine("Free parking spaces: {0}", Parking.ParkingSpace);
                    break;

                case "9":
                    Console.WriteLine("Occupied parking spaces: {0}/{1}", Settings.parkingSpaceLimit - Parking.ParkingSpace,
                                      Settings.parkingSpaceLimit);
                    break;

                case "10":
                    Environment.Exit(0);
                    return;

                default:
                    Console.WriteLine("Please enter only existing menu option numbers!");
                    break;
                }
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            Parking myParking = new Parking();

            Console.WriteLine("Hello in my parking lot!'\n" +
                              "1) Find out the current balance of parking\n" +
                              "2) The amount of money earned in the last minute\n" +
                              "3) Find out the number of free / busy places in the parking lot\n" +
                              "4) Show all transactions in the last minute\n" +
                              "5) Print the entire Transaction history (after reading the data from the Transactions.log file)\n" +
                              "6) Display the list of all vehicles\n" +
                              "7) Createthe vehicle\n" +
                              "8) Remove parking vehicle\n" +
                              "9) Refill the balance of a particular vehicle\n");

            string input;

            do
            {
                input = Console.ReadLine();
                switch (input)
                {
                case "1":
                    Console.WriteLine(myParking.Balance);
                    break;

                case "2":
                    myParking.EarnedMoneyForLastMinute();
                    break;

                case "3":
                    myParking.ShowPlaces();
                    break;

                case "4":
                    myParking.ShowLastTransactions();
                    break;

                case "5":
                    myParking.ShowAllTransactions();
                    break;

                case "6":
                    myParking.ShowCar();
                    break;

                case "7":
                    myParking.addCar();
                    break;

                case "8":
                    myParking.RemoveCar();

                    break;

                case "9":
                    myParking.AddMoney();
                    break;
                }
            } while (true);
        }