Ejemplo n.º 1
0
        // Add Vehicle and Print it
        public void AddPrintPark(GarageHandler garageHandler, string valueKey)
        {
            string valueregNo;
            string valueColor;
            int    IntValue;

            printAction("Enter vehicle regNo:");
            valueregNo = Console.ReadLine();

            printAction("Enter vehicle color:");
            valueColor = Console.ReadLine();

            if (valueKey == "1")
            {
                IntValue = InputVehiclePark(valueKey);
                garageHandler.Add(new Cars("car", valueregNo, valueColor, 4, IntValue));
                printAction($"This car  park: {valueregNo}, {valueColor}, {4},{IntValue}");
            }
            else if (valueKey == "2")
            {
                IntValue = InputVehiclePark(valueKey);
                garageHandler.Add(new Motorcycles("motorcycle", valueregNo, valueColor, 2, IntValue));
                printAction($"This motorcycle park:  {valueregNo}, {valueColor}, {2},{IntValue} ");
            }
            else if (valueKey == "3")
            {
                IntValue = InputVehiclePark(valueKey);
                garageHandler.Add(new Mopeds("Mopeds", valueregNo, valueColor, 2, IntValue));
                printAction($"This mopeds park: {valueregNo}, {valueColor}, {2},{IntValue}");
            }
            else if (valueKey == "4")
            {
                IntValue = InputVehiclePark(valueKey);
                garageHandler.Add(new Airplane("Airplane", valueregNo, valueColor, 2, IntValue));
                printAction($"This airplane park:  {valueregNo}, {valueColor},{2},{IntValue}");
            }
            else if (valueKey == "5")
            {
                IntValue = InputVehiclePark(valueKey);
                garageHandler.Add(new Bus("Bus", valueregNo, valueColor, 4, IntValue));
                printAction($"This bus park:  {valueregNo}, {valueColor},{4},{IntValue}");
            }
            else if (valueKey == "6")
            {
                IntValue = InputVehiclePark(valueKey);
                garageHandler.Add(new Boat("Boat", valueregNo, valueColor, 0, IntValue));
                printAction($"This boat park:  {valueregNo}, {valueColor},{0},{IntValue}");
            }
            else if (valueKey == "7")
            {
                IntValue = InputVehiclePark(valueKey);
                garageHandler.Add(new Bicycle("Bicycle", valueregNo, valueColor, 2, IntValue));
                printAction($"This bicycle park: {valueregNo}, {valueColor},{2},{IntValue}");
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            //Action<string> printActioMain = i => Console.WriteLine(i);

            UI  ui            = new UI();
            var garageHandler = new GarageHandler(10);
            var garage        = new Garage <Vehicle>(20);

            garageHandler.Add(new Cars("Car", "112AB", "red", 4, 12));
            garageHandler.Add(new Cars("Car", "112B", "red", 4, 12));
            garageHandler.Add(new Motorcycles("motorcycles", "112b", "green", 2, 13));
            garageHandler.Add(new Motorcycles("motorcycles", "112b", "green", 2, 13));
            garageHandler.Add(new Airplane("Airplane", "132AA", "red", 2, 15));
            garageHandler.Add(new Bus("Bus", "132aa", "white", 2, 1));



            while (true)
            {
                Console.WriteLine("Please navigate through the menu by inputting the number \n(1, 2, 3 ,4, 5, 6, 7, 0) of your choice"

                                  + "\n1. List all parked vehicles"
                                  + "\n2. List all vehicle types currently parked in the garage and how many of each kind"
                                  + "\n3. Park and unpark specific vehicles from the garage"
                                  + "\n4. Find a vehicles based on color and wheels "
                                  + "\n5. Search on a vehicle based on Reg Number"
                                  + "\n6. Set maximum capacity of the Garage "
                                  + "\n7. Save and load from File"
                                  + "\n0. Exit the application");

                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':

                    foreach (var v in garageHandler.GetVehicleInfo())
                    {
                        Console.WriteLine($"this vehicle park: {v.Name}, {v.Color}, {v.RegNo}");
                    }
                    break;

                case '2':

                    garageHandler.CountVehicleHandler();
                    break;

                case '3':

                    Console.WriteLine("Type '+' or '-'  to park or unpark from the Garage or zero to exit :");
                    string input1 = Console.ReadLine();
                    char   nav    = input1[0];

                    ui.ParkUnPark(nav, input1, garageHandler);
                    break;

                case '4':

                    Console.WriteLine("Enter vehicle color:");
                    string valueColor = Console.ReadLine();
                    Console.WriteLine("Enter vehicle numWheels:");
                    string valuenumWheels = Console.ReadLine();

                    garageHandler.FindVehicleColorwheelsHandler(valueColor, ui.Validinput(valuenumWheels));
                    break;

                case '5':

                    Console.WriteLine("Enter vehicle Reg number:");
                    string valueRegNum = Console.ReadLine();

                    garageHandler.SearchVehicleHandler(valueRegNum);
                    break;

                case '6':

                    Console.WriteLine("Please enter garage capacity:");
                    string input2 = Console.ReadLine();

                    garageHandler.CapacityGarageHandler(input2);
                    break;


                case '7':

                    //GarageFile obj = new GarageFile();
                    //obj.id = 1;
                    //obj.name = ".Net";


                    IFormatter formatter = new BinaryFormatter();
                    FileStream stream    = new FileStream(@"C:\Users\Elev\Desktop\ExampleNew.txt", FileMode.Create, FileAccess.Write);

                    formatter.Serialize(stream, garage);
                    stream.Close();

                    stream = new FileStream(@"C:\Users\Elev\Desktop\ExampleNew.txt", FileMode.Open, FileAccess.Read);
                    Garage <Vehicle> objnew = (Garage <Vehicle>)formatter.Deserialize(stream);
                    foreach (var v in garage)
                    {
                        Console.WriteLine($"this vehicle park: {v.Name}, {v.Color}, {v.RegNo}");
                    }


                    //Console.WriteLine(objnew.name);
                    //Console.WriteLine(objnew.id);
                    Console.ReadKey();

                    break;

                case '0':
                    return;

                default:
                    Console.WriteLine("Please enter some valid input (0, 1, 2, 3, 4, 5, 6)");
                    break;
                }
            }
        }