Example #1
0
        public void addVehicle(Garage <Vehicle> garage)
        {
            Console.Clear();
            Console.WriteLine("input the number \n(1, 2, 3 ,4, 0) of your choice\n"
                              + "\n1. Add a Car"
                              + "\n2. Add a Motorcycle"
                              + "\n0. Return to main menu");
            char input = ' '; //Creates the character input to be used with the switch-case below.

            try
            {
                input = Console.ReadLine()[0]; //Tries to set input to the first char in an input line
            }
            catch (IndexOutOfRangeException)   //If the input line is empty, we ask the users for some input.
            {
                Console.Clear();
                Console.WriteLine("Please enter some input!");
            }

            switch (input)
            {
            case '1':
                Console.WriteLine("Ange regnr");
                string regnr = Console.ReadLine();
                Console.WriteLine("Ange antal dörrar på bilen");
                int doors = Int16.Parse(Console.ReadLine());
                Car c     = new Car(regnr, "Volvo", "White");
                c.nrOfDoors = doors;
                garage.AddVehicle(c);
                break;

            case '2':
                Console.WriteLine("Ange regnr");
                regnr = Console.ReadLine();
                Console.WriteLine("Är din MC en riskokare? (J / N) ");
                bool       rice = Console.ReadLine().Equals("J");
                Motorcycle mc   = new Motorcycle(regnr, "Yamaha", "White");
                mc.isRiceCooker = rice;
                garage.AddVehicle(mc);
                break;

            case '0':
                return;

            default:
                Console.WriteLine("Please enter some valid input (0, 1, 2, 3, 4)");
                break;
            }
        }
Example #2
0
 public static void seed(Garage <Vehicle> garage)
 {
     garage.AddVehicle(new Car("A", "Toyota", "Red")
     {
         nrOfDoors = 2
     });
     garage.AddVehicle(new Car("B", "Porsche", "Blue")
     {
         nrOfDoors = 4
     });
     garage.AddVehicle(new Motorcycle("C", "Yamaha", "Black")
     {
         isRiceCooker = true
     });
     garage.AddVehicle(new Motorcycle("D", "Harley Davidson", "White")
     {
         isRiceCooker = false
     });
     garage.AddVehicle(new Airplane("E", "Cessna", "White")
     {
         wingspan = 20
     });
     garage.AddVehicle(new Airplane("F", "Cessna", "Yellow")
     {
         wingspan = 2
     });
 }