コード例 #1
0
        public string AskForColor()
        {
            //todo: formatting and checking
            Console.Write("\nColor: ");
            string color = Console.ReadLine();

            return(Extra.CAPITALFormatting(color));
        }
コード例 #2
0
        private void Init()
        {
            mainMenu = new Menu(Extra.NormalFormatting("main"), new Dictionary <char, MenuMap>   {
                { 'q', new MenuMap("End program", Quit) },
                { 'a', new MenuMap("List all parked", theGarage.ListAll) },
                { 't', new MenuMap("List types and quantity", theGarage.ListAllTypes) },
                { 'c', new MenuMap("Add/remove vehicles", AddRemove) },
                { 's', new MenuMap("Search by reg", SearchReg) },
                { 'p', new MenuMap("Search by propertie(s)", SearchProperties) } //sedan: hantera tomma fält som alla träffar
            });

            theGarage.AddDummys();
        }
コード例 #3
0
        public string AskForReg()
        {
            //todo: formatting and checking
            Console.Write("\nReg number: ");
            string regnr = Console.ReadLine();

            regnr = Extra.CAPITALFormatting(regnr);
            if (Lookup(regnr) < 0)
            {
                return(regnr);
            }
            else
            {
                return(null);
            }
            //return Extra.CAPITALFormatting(regnr);
        }
コード例 #4
0
        public int RegLookup(string searchReg)
        {
            int found = -1;
            int count = 0;

            searchReg = Extra.CAPITALFormatting(searchReg);

            foreach (var ch in garage)
            {
                if (searchReg == ch.RegNumber)
                {
                    return(count);
                }
                count++;
            }
            return(found);
        }
コード例 #5
0
        public void AddDummys() //denna är inte så noga, men den avslöjar ett tankefel med att lägga till poster (dubletter kollas på fel nivå)
        {
            foreach (var i in Extra.GetIteratorVehicles())
            {
                string typeToAdd = i.GetType().Name;
                typeToAdd = Extra.NormalFormatting(typeToAdd);

                Console.WriteLine(typeToAdd);

                string foundType = null;

                foreach (var ch in types)
                {
                    if (typeToAdd == ch.Name)
                    {
                        foundType = ch.Name;
                    }
                }

                if (foundType == null)
                {
                    //TODO: loop again
                    Console.WriteLine("non existant type or no input!");
                }
                else
                {
                    Console.WriteLine(foundType);
                    //TODO: add type specifics and then the shared stuff and then add
                    int empty = garage.FirstEmpty();
                    if (empty >= 0)
                    {
                        Vehicle t = i;
                        t.RegNumber = t.RegNumber.ToUpper();
                        t.Color     = t.Color.ToUpper();
                        Console.WriteLine("adding " + t.RegNumber + ". //foundtype: " + foundType);
                        garage.Add(garage.FirstEmpty(), t);
                    }
                    else
                    {
                        Console.WriteLine("garage full");
                    }
                }
            }
        }
コード例 #6
0
        //public Queue<Vehicle> Lookup(Vehicle toLookup)
        //{
        //    var lookedUp = new Queue<Vehicle>();

        //    /*
        //     *
        //     *   Vehicle toSearch;
        //    Console.WriteLine("\r\n\r\nFill the fields you wanna search, leave rest empty... ");
        //    Console.Write("type: ");
        //    string type = Console.ReadLine(); //todo: make formatting correct
        //    Console.Write("regnr: ");
        //    string reg = Console.ReadLine().ToUpper(); //todo: check formatting
        //    Console.Write("color: ");
        //    string color= Console.ReadLine().ToUpper(); //todo: check formatting
        //    Console.Write("number of wheels: ");
        //    string wheels = Console.ReadLine(); //todo: fix checking
        //    int nowheels = Int32.Parse(wheels);

        //    Console.Write("max altitude: "); //plane - todo: maybe an abstract function that handles all specific input
        //                                        //the same in each derived
        //    Console.Write("weight: "); //boat
        //    Console.Write("max number of passengers: "); //bus
        //    Console.Write("gasoline consumption: "); //car
        //    Console.Write("top speed"); //motorcycle


        //    if (type == "Airplane")
        //    {
        //        double maxalt = AskForMaxAltitude();
        //        toSearch = new Airplane(reg, color, nowheels, maxalt); //todo: add with proper layering
        //    }
        //    else if (type == "Boat")
        //    {
        //        double weight = AskForWeight();
        //        toSearch = new Boat(reg, color, nowheels, weight);
        //    }
        //    else if (type == "Bus")
        //    {
        //        int passengers = AskForPassengers();
        //        toSearch = new Bus(reg, color, nowheels, passengers);
        //    }
        //    else if (type == "Car")
        //    {
        //        double gasolineconsumption = AskForGasolineConsumption();
        //        toSearch = new Car(reg, color, nowheels, gasolineconsumption);
        //    }
        //    else if (type == "Motorcycle")
        //    {
        //        double topspeed = AskForTopSpeed();
        //        toSearch = new Motorcycle(reg, color, nowheels, topspeed);
        //    }
        //    else return; //todo: fix bool error return
        //    //theGarage.Add(toAdd);

        //     */


        //    /*

        //    string type = toLookup.GetType().Name;
        //    string regnr = toLookup.RegNumber;
        //    string color = toLookup.Color;
        //    int nowheels = toLookup.NoWheels;
        //    double maxalt=-1;
        //    double weight=-1;
        //    int passengers=-1;
        //    double gasolineconsumption=-1;
        //    double topspeed=-1;
        //    Vehicle searchObject;
        //    switch(type) //could be generalised but time flies
        //    {
        //        case "Airplane":
        //            maxalt = double.Parse(toLookup.GetSpecific());//todo: formatting
        //            searchObject = new Airplane(regnr, color, nowheels, maxalt);
        //            break;
        //        case "Boat":
        //            weight = double.Parse(toLookup.GetSpecific());
        //            break;
        //        case "Bus":
        //            passengers = Int32.Parse(toLookup.GetSpecific());
        //            break;
        //        case "Car":
        //            gasolineconsumption = Int32.Parse(toLookup.GetSpecific());
        //            break;
        //        case "Motorcycle":
        //            topspeed = Int32.Parse(toLookup.GetSpecific());
        //            break;
        //        default:
        //            break;
        //    }  todo: implement all posibilty to search all fields later */
        //    string searchType = toLookup.GetType().Name; //todo: formatting
        //    string searchReg = toLookup.RegNumber;
        //    string searchColor = toLookup.Color;
        //    int searchWheels = toLookup.NoWheels;

        //    foreach (var ch in garage)
        //    {
        //        string parkedTyped = ch.GetType().Name;
        //        string parkedReg = ch.RegNumber;
        //        string parkedColor = ch.Color;
        //        int parkedWheels = ch.NoWheels;
        //        if (string.IsNullOrEmpty(searchType)) searchType = parkedTyped;
        //        if (string.IsNullOrEmpty(searchReg)) searchReg = parkedReg;
        //        if (string.IsNullOrEmpty(searchColor)) searchColor = parkedColor;
        //    }
        //    return (lookedUp);
        //}

        public string AskForType()
        {
            Console.Write("\nType (valid types:  ");
            foreach (var ch in types)
            {
                Console.Write($" {ch.Name} ");
            }
            Console.Write("): ");
            string type = Console.ReadLine();

            type = Extra.NormalFormatting(type);

            //todo: format and check chars

            foreach (var ch in types)
            {
                if (type == ch.Name)
                {
                    return(type);
                }
            }
            Console.WriteLine("invalid type!");
            return(null);
        }
コード例 #7
0
        void SearchProperties()
        {
            Vehicle toSearch = null;

            Console.WriteLine("\r\n\r\nFill the fields you wanna search, leave rest empty... ");
            Console.Write("type: ");
            string type = Extra.NormalFormatting(Console.ReadLine()); //todo: make formatting correct

            Console.Write("regnr: ");
            string reg = Extra.CAPITALFormatting(Console.ReadLine()); //todo: check formatting

            Console.Write("color: ");
            string color = Extra.CAPITALFormatting(Console.ReadLine().ToUpper()); //todo: check formatting

            Console.Write("number of wheels: ");
            string wheels   = Console.ReadLine(); //todo: fix checking
            int    nowheels = -1;

            if (!string.IsNullOrEmpty(wheels))  //nowheels = Int32.tr(wheels); //todo:  formatting
            {
                if (!Int32.TryParse(wheels, out nowheels))
                {
                    Console.WriteLine("unable to parse");
                }
            }

            if (type == "Airplane") //jag gillar inte den här specifika koden ..
            {
                double maxalt = theGarage.AskForMaxAltitude();
                toSearch = new Airplane(reg, color, nowheels, maxalt); //todo: add with proper layering
            }
            else if (type == "Boat")
            {
                double weight = theGarage.AskForWeight();
                toSearch = new Boat(reg, color, nowheels, weight);
            }
            else if (type == "Bus")
            {
                int passengers = theGarage.AskForPassengers();
                toSearch = new Bus(reg, color, nowheels, passengers);
            }
            else if (type == "Car")
            {
                double gasolineconsumption = theGarage.AskForGasolineConsumption();
                toSearch = new Car(reg, color, nowheels, gasolineconsumption);
            }
            else if (type == "Motorcycle")
            {
                double topspeed = theGarage.AskForTopSpeed();
                toSearch = new Motorcycle(reg, color, nowheels, topspeed);
            }
            else
            {
                toSearch = new Vehicle(reg, color, nowheels);
            }

            var searchItems = new Queue <Vehicle>(theGarage.Lookup(toSearch.GetType().Name,
                                                                   toSearch.RegNumber,
                                                                   toSearch.Color,
                                                                   toSearch.NoWheels));

            while (searchItems.Count > 0)
            {
                var t = searchItems.Dequeue();
                Console.WriteLine("found: " + t.Color);
            }
        }