예제 #1
0
 public void ShowAllCar(List <Car> cars = null)
 {
     if (cars == null)
     {
         Console.WriteLine("[Your cars]");
         cars = this.my_cars;
     }
     for (int i = 0; i < cars.Count; i++)
     {
         Console.WriteLine("[Parking space " + (i + 1) + "]");
         Garash.ShowCar(cars[i]);
     }
 }
예제 #2
0
    static void Main()
    {
        Garash Sheiha = new Garash();
        Car    bmw    = new Car()
        {
            name = "bmw", color = "red", speed = 170, year = 2019
        };
        Car bmw2 = new Car()
        {
            name = "bmw", color = "red", speed = 170, year = 2018
        };
        Car jimny = new Car()
        {
            name = "Tesla", color = "red", speed = 150, year = 2017
        };

        Sheiha.cars.Add(bmw);
        Sheiha.cars.Add(bmw2);
        Sheiha.cars.Add(jimny);
        Sheiha.Using();
    }
예제 #3
0
    static void Main()
    {
        // create Garash Sheiha
        Garash Sheiha = new Garash();
        // my cars
        Car toyota_big = new Car()
        {
            model = "toyota rav4", color = "red", speed = 170, create_year = 2019
        };
        Car toyota_mini = new Car()
        {
            model = "toyota yaris", color = "red", speed = 170, create_year = 2019
        };

        // adding cars in Garash
        Sheiha.my_cars.Add(toyota_big);
        Sheiha.my_cars.Add(toyota_mini);
        Sheiha.ShowAllCar();
        Console.WriteLine();

        // buy a car
        Console.WriteLine("[Byu a car]");
        Sheiha.ByuCar();
        Sheiha.ShowAllCar();

        Console.WriteLine();
        // delete a car
        Console.WriteLine("[delete a car]");
        Sheiha.DeleteCar();
        Sheiha.ShowAllCar();

        Console.WriteLine();
        // Drive a car
        Console.WriteLine("[Drive a car]");
        Sheiha.DriveCar();
    }
예제 #4
0
    public void DriveCar(List <Car> cars = null)
    {
        if (cars == null)
        {
            cars = this.my_cars;
        }
        List <int> old_parametr = new List <int>();

        Console.WriteLine(cars.Count);

        while (cars.Count > 1 || cars.Count == 0)
        {
            if (cars.Count == 0)
            {
                Console.WriteLine("Your not have car");
                return;
            }
            this.ShowAllCar(cars);
            Console.WriteLine("select creteria");
            string [] parametrs = { "model", "color", "speed", "year" };

            for (int i = 0; i < parametrs.Length; i++)
            {
                bool flag = false;
                for (int j = 0; j < old_parametr.Count; j++)
                {
                    if ((i + 1) == old_parametr[j])
                    {
                        flag = true;
                    }
                }
                if (flag == false)
                {
                    Console.Write((i + 1) + ")" + parametrs[i] + " ");
                }
            }
            Console.WriteLine();
            int k = 0;
            do
            {
                Console.Write("filter=");
                k = Convert.ToInt32(Console.ReadLine());
                if (k < 1 || k > 4)
                {
                    Console.WriteLine("Invalide value");
                }
            }while(k < 1 || k > 4);
            old_parametr.Add(k);
            switch (k)
            {
            case 1:
                Console.WriteLine("model:");
                string model = Console.ReadLine();
                cars = this.SearchName(model);
                break;

            case 2:
                Console.WriteLine("color:");
                string color = Console.ReadLine();
                cars = this.SearchColor(color);
                break;

            case 3:
                Console.WriteLine("speed:");
                int speed = Convert.ToInt32(Console.ReadLine());
                cars = this.SearchSpeed(speed);
                break;

            case 4:
                Console.WriteLine("year:");
                int year = Convert.ToInt32(Console.ReadLine());
                cars = this.SearchYear(year);
                break;
            }
        }
        if (cars.Count == 0)
        {
            Console.WriteLine("your have not car with creteria");
        }
        else
        {
            Console.WriteLine("[You select car ]");
            Garash.ShowCar(cars[0]);
        }
        Console.WriteLine("----------------------------------");
    }