public static IDwelling GenerateDwelling(HouseType type, string postCode, string identifier, string householderName, int residents, bool singleFloored = true)
        {
            IDwelling result = null;

            switch (type)
            {
            case HouseType.Bungalow:
                Bungalow bungalow = new Bungalow(postCode, identifier);
                bungalow.HouseholderName = householderName;
                bungalow.Residents       = residents;
                result = bungalow;
                break;

            case HouseType.Flat:
                Flat flat = new Flat(postCode, identifier);
                flat.HouseholderName = householderName;
                flat.Residents       = residents;
                result = flat;
                break;

            default:
                //HouseType.House
                House house = new House(postCode, identifier);
                house.HouseholderName = householderName;
                house.Residents       = residents;
                house.SingleFloored   = singleFloored;
                result = house;
                break;
            }

            return(result);
        }
Beispiel #2
0
        public void DeleteDwelling(string search)
        {
            int hash = Math.Abs(search.GetHashCode());

            for (int i = 0; i < Size; i++)
            {
                int       testingHash = (hash + i * i) % Size;
                IDwelling dwelling    = this.Storage[testingHash];

                if (dwelling != null && dwelling.PostCode + dwelling.Identifier == search)
                {
                    this.Storage[testingHash] = null;
                }
            }
        }
Beispiel #3
0
        public void AddDwelling(IDwelling dwelling)
        {
            int hash = Math.Abs(dwelling.GetHashCode());

            //quadratic probing
            for (int i = 0; i < this.Size; i++)
            {
                int tryHashLocation = (hash + i * i) % Size;

                if (Storage[tryHashLocation] == null)
                {
                    Storage[tryHashLocation] = dwelling;
                }
            }
        }
Beispiel #4
0
        public override bool Submit()
        {
            string postCode        = this.GetInputByIndex(0);
            string identifier      = this.GetInputByIndex(1);
            string householderName = this.GetInputByIndex(2);
            string residents       = this.GetInputByIndex(3);

            int  residentsNum      = 0;
            bool singleFlooredBool = true;

            if (!Int32.TryParse(residents, out residentsNum))
            {
                this.ErrorMessage = "The string entered into Residents was not a number!";
                return(false);
            }

            if (this.InputAreas.Length > 4)
            {
                string singleFloored = this.GetInputByIndex(4).ToLower();

                if (singleFloored == "y")
                {
                    singleFlooredBool = true;
                }
                else if (singleFloored == "n")
                {
                    singleFlooredBool = false;
                }
                else
                {
                    this.ErrorMessage = "The value entered for Single Floored was not one of the accepted values!";
                    return(false);
                }
            }

            IDwelling existingDwelling = Program.DwellingHashStorage.GetDwelling(postCode + identifier);

            if (existingDwelling != null && existingDwelling.PostCode == postCode && existingDwelling.Identifier == identifier)
            {
                this.ErrorMessage = "A dwelling with the same post code and identifier already exists!";
                return(false);
            }

            Program.DwellingHashStorage.AddDwelling(DwellingFactory.GenerateDwelling((HouseType)Program.MenuManager.GetPersistentMenuData("housetype"), postCode, identifier, householderName, residentsNum, singleFlooredBool));
            Program.MenuManager.ChangeMenu(new MainMenu());

            return(true);
        }
Beispiel #5
0
        public IDwelling GetDwelling(string search)
        {
            int hash = Math.Abs(search.GetHashCode());

            for (int i = 0; i < Size; i++)
            {
                int       location = (hash + i * i) % Size;
                IDwelling dwelling = this.Storage[location];
                if (dwelling != null && dwelling.PostCode + dwelling.Identifier == search)
                {
                    return(dwelling);
                }
            }

            return(null);
        }
Beispiel #6
0
        public override bool Submit()
        {
            IDwelling dwelling = Program.DwellingHashStorage.GetDwelling(this.GetInputByIndex(0) + this.GetInputByIndex(1));

            if (dwelling != null)
            {
                Program.MenuManager.ChangeMenu(new ViewDwellingMenu(dwelling));
            }
            else
            {
                this.ErrorMessage = "Could not find matching Dwelling!";
                return(false);
            }

            return(true);
        }
Beispiel #7
0
        public override bool Submit()
        {
            IDwelling dwelling = Program.DwellingHashStorage.GetDwelling(this.GetInputByIndex(0) + this.GetInputByIndex(1));

            if (dwelling != null)
            {
                Program.DwellingHashStorage.DeleteDwelling(this.GetInputByIndex(0) + this.GetInputByIndex(1));//Program.MenuManager.ChangeMenu(new ViewDwellingMenu(dwelling));
                Console.Clear();
                Console.SetCursorPosition(2, 10);
                Console.WriteLine("Successfully deleted Dwelling!");
                System.Threading.Thread.Sleep(1000);

                Program.MenuManager.ChangeMenu(new MainMenu());
            }
            else
            {
                this.ErrorMessage = "Could not find matching Dwelling!";
                Program.Renderer.Render();
                return(false);
            }

            return(true);
        }
Beispiel #8
0
 public ViewDwellingMenu(IDwelling dwelling)
 {
     this.Dwelling = dwelling;
 }