Exemplo n.º 1
0
        private static void checkCarColor(string i_CarColorStringFormat, ref Car.CarColor io_CarColor)
        {
            if (i_CarColorStringFormat != "1" && i_CarColorStringFormat != "2" &&
                i_CarColorStringFormat != "3" && i_CarColorStringFormat != "4")
            {
                throw new FormatException("Bad Input Chose one Number From (1-4)");
            }

            io_CarColor = (Car.CarColor) int.Parse(i_CarColorStringFormat);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            int choice = 3;

            switch (choice)
            {
            //cars
            case 1:
                List <Car> cars = new List <Car>();
                //int count = 0;
                for (int i = 0; i < 256; i++)
                {
                    Random       random      = new Random();
                    Array        type        = Enum.GetValues(typeof(Car.CarType));
                    Array        color       = Enum.GetValues(typeof(Car.CarColor));
                    Car.CarType  randomType  = (Car.CarType)type.GetValue(random.Next(type.Length));
                    Car.CarColor randomColor = (Car.CarColor)type.GetValue(random.Next(color.Length));
                    cars.Add(new Car(randomType, randomColor));
                }

                foreach (var car in CountSameType(cars))
                {
                    Console.WriteLine(car.Key + "-->" + car.Value);
                }
                foreach (var car in CountSameColor(cars))
                {
                    Console.WriteLine(car.Key + "-->" + car.Value);
                }
                Console.WriteLine(MostFrequentCar(cars));
                break;

            //cards
            case 2:
                Console.WriteLine("Welcome to card game");
                Game cardGame = new Game();
                cardGame.AskDraw();
                break;

            //product tuple
            case 3:
                Product p = new Product("brush", 20, 30);
                var(name, oprice, nprice) = p.GetDiscount();
                Console.WriteLine($"name {name} old price {oprice} new price {nprice}");
                break;
            }
        }
Exemplo n.º 3
0
        private static Car.CarColor getCarColor()
        {
            Car.CarColor carColor = 0;
            carColorLabel();
            carColorInstructiontMessage();
            carColorInputMessage();
            string carColorString = Console.ReadLine();

            try
            {
                checkCarColor(carColorString, ref carColor);
            }
            catch (FormatException ex)
            {
                Console.WriteLine(ex.Message);
                carColor = getCarColor();
            }

            return(carColor);
        }