Example #1
0
        /// <summary>
        /// Does the remove command.
        /// </summary>
        /// <param name="zoo"> The zoo from which the animal will be removed from.</param>
        /// <param name="type"> The type of animal being removed.</param>
        /// <param name="name"> The name of the animal being removed.</param>
        public static void ProcessRemoveCommand(Zoo zoo, string type, string name)
        {
            switch (type)
            {
            // If the type is animal...
            case "animal":

                // Capitalizes the first letter of the name variable.
                string upperName = ConsoleUtil.InitialUpper(name);

                // Removes the animal from the zoo based on their name.
                RemoveAnimal(zoo, upperName);

                break;

            // If the type is guest...
            case "guest":

                // Capitalizes the first letter of the name variable.
                string upperGuest = ConsoleUtil.InitialUpper(name);

                // Removes the guest from the zoo based on their name.
                RemoveGuest(zoo, upperGuest);

                break;

            // Otherwise display error.
            default:

                Console.WriteLine("This command only supoorts removing animals.");

                break;
            }
        }
Example #2
0
        /// <summary>
        /// Reads the gender of the item.
        /// </summary>
        /// <returns>The Gender of the item.</returns>
        public static Gender ReadGender()
        {
            Gender result = Gender.Female;

            string stringValue = result.ToString();

            bool found = false;

            while (!found)
            {
                stringValue = ConsoleUtil.ReadAlphabeticValue("Gender");

                stringValue = ConsoleUtil.InitialUpper(stringValue);

                // If a matching enumerated value can be found...
                if (Enum.TryParse <Gender>(stringValue, out result))
                {
                    found = true;
                }
                else
                {
                    Console.WriteLine("Invalid gender.");
                }
            }

            return(result);
        }
Example #3
0
        /// <summary>
        /// Directs the show command according to its parameter.
        /// </summary>
        /// <param name="zoo">The zoo created.</param>
        /// <param name="type">The type of parameter via commandWords[1]: animal or guest.</param>
        /// <param name="name">The name of the animal or guest to find.</param>
        public static void ProcessShowCommand(Zoo zoo, string type, string name)
        {
            string animalName = ConsoleUtil.InitialUpper(name);
            string guestName  = ConsoleUtil.InitialUpper(name);

            switch (type)
            {
            case "animal":
                ShowAnimal(zoo, animalName);

                break;

            case "guest":
                ShowGuest(zoo, guestName);

                break;

            case "cage":
                ShowCage(zoo, animalName);

                break;

            case "children":
                ShowChildren(zoo, animalName);
                break;
            }
        }
        /// <summary>
        /// Processes the show console command.
        /// </summary>
        /// <param name="zoo">The zoo containing the object to show.</param>
        /// <param name="type">The type of object to show.</param>
        /// <param name="name">The name of the object to show.</param>
        public static void ProcessShowCommand(Zoo zoo, string type, string name)
        {
            string uppercaseName = ConsoleUtil.InitialUpper(name);

            switch (type)
            {
            case "animal":
                ConsoleHelper.ShowAnimal(zoo, uppercaseName);

                break;

            case "guest":
                ConsoleHelper.ShowGuest(zoo, uppercaseName);

                break;

            case "cage":
                ConsoleHelper.ShowCage(zoo, uppercaseName);

                break;

            case "children":
                ConsoleHelper.ShowChildren(zoo, uppercaseName);

                break;

            default:
                Console.WriteLine("Unknown type. Only animals and guests can be shown.");

                break;
            }
        }
Example #5
0
        /// <summary>
        /// Show the commands of the console.
        /// </summary>
        /// <param name="zoo"> The zoo being processed.</param>
        /// <param name="type"> The type being processed.</param>
        /// <param name="name"> The name being processed.</param>
        public static void ProcessShowCommand(Zoo zoo, string type, string name)
        {
            string upperName = ConsoleUtil.InitialUpper(name);

            switch (type)
            {
            case "animal":
                ShowAnimal(zoo, upperName);

                break;

            case "cage":
                ShowCage(zoo, upperName);

                break;

            case "childern":
                ShowChildern(zoo, upperName);

                break;

            case "guest":
                ShowGuest(zoo, upperName);

                break;

            default:
                throw new Exception($"Sorry, but {type} is not a type, Only animals and guests can be shown.");
            }
        }
Example #6
0
        /// <summary>
        /// Shows the animal in the zoo.
        /// </summary>
        /// <param name="zoo"> The zoo the animal is in.</param>
        /// <param name="name"> The name of the animal.</param>
        private static void ShowAnimal(Zoo zoo, string name)
        {
            try
            {
                // Finds the animal by name.
                Animal animalFound = null;

                string animalName = ConsoleUtil.InitialUpper(name);

                animalFound = zoo.FindAnimal(animalName);

                if (animalFound != null)
                {
                    Console.WriteLine("The following animal was found: " + (animalFound));
                }
                else
                {
                    Console.WriteLine("The animal could not be found.");
                }
            }
            catch (ArgumentOutOfRangeException)
            {
                Console.WriteLine("Must enter a valid command.");
            }
            catch (FormatException)
            {
                Console.WriteLine("Must be letters.");
            }
            catch (IndexOutOfRangeException)
            {
                Console.WriteLine("Must be the name of an animal.");
            }
        }
Example #7
0
        /// <summary>
        /// The type of animal being read.
        /// </summary>
        /// <returns> The type of animal.</returns>
        public static AnimalType ReadAnimalType()
        {
            AnimalType result = AnimalType.Dingo;

            string stringValue = result.ToString();

            bool found = false;

            while (!found)
            {
                stringValue = ConsoleUtil.ReadAlphabeticValue("AnimalType");

                stringValue = ConsoleUtil.InitialUpper(stringValue);

                // If a matching enumerated value can be found...
                if (Enum.TryParse <AnimalType>(stringValue, out result))
                {
                    found = true;
                }
                else
                {
                    Console.WriteLine("Invalid animal type.");
                }
            }

            return(result);
        }
Example #8
0
        /// <summary>
        /// Reads the color that was set for the wallet.
        /// </summary>
        /// <returns> The wallet color.</returns>
        public static WalletColor ReadWalletColor()
        {
            WalletColor result = WalletColor.Black;

            string stringValue = result.ToString();

            bool found = false;

            while (!found)
            {
                stringValue = ConsoleUtil.ReadAlphabeticValue("Wallet Color");

                stringValue = ConsoleUtil.InitialUpper(stringValue);

                // If a matching enumerated value can be found...
                if (Enum.TryParse <WalletColor>(stringValue, out result))
                {
                    found = true;
                }
                else
                {
                    Console.WriteLine("Invalid wallet color.");
                }
            }

            return(result);
        }
Example #9
0
        /// <summary>
        /// Shows the guest in the zoo.
        /// </summary>
        /// <param name="zoo"> The zoo that guest is in.</param>
        /// <param name="name"> The name of the guest.</param>
        private static void ShowGuest(Zoo zoo, string name)
        {
            try
            {
                Guest guestFound = null;

                string guestName = ConsoleUtil.InitialUpper(name);

                guestFound = zoo.FindGuest(guestName);

                if (guestFound != null)
                {
                    Console.WriteLine("The following guest was found: " + (guestFound));
                }
                else
                {
                    Console.WriteLine("The guest could not be found");
                }
            }

            catch (FormatException)
            {
                Console.WriteLine("Must be letters.");
            }
            catch (IndexOutOfRangeException)
            {
                Console.WriteLine("Must be the name of a guest in the list of guests..");
            }
        }
Example #10
0
        /// <summary>
        /// Shows the animal's cage.
        /// </summary>
        /// <param name="zoo">The zoo with the cage.</param>
        /// <param name="animalName">The intended animal.</param>
        private static void ShowCage(Zoo zoo, string animalName)
        {
            string animal = ConsoleUtil.InitialUpper(animalName);

            Animal animalResult = zoo.FindAnimal(animal);

            Cage cage = zoo.FindCage(animalResult.GetType());

            Console.WriteLine(cage.ToString());
        }
Example #11
0
        /// <summary>
        /// Shows the desired animal.
        /// </summary>
        /// <param name="zoo">The zoo created.</param>
        /// <param name="name">The name of the animal to be shown via parameter commandWords[2].</param>
        private static void ShowAnimal(Zoo zoo, string name)
        {
            string animalName = ConsoleUtil.InitialUpper(name);
            Animal animal     = zoo.FindAnimal(animalName);

            if (animal != null)
            {
                Console.WriteLine($"The following animal was found: {animal}.");
            }
            else
            {
                Console.WriteLine("The animal could not be found.");
            }
        }
Example #12
0
        /// <summary>
        /// Shows the desired guest.
        /// </summary>
        /// <param name="zoo">The zoo created.</param>
        /// <param name="name">The name of the guest to be shown via parameter commandWords[2].</param>
        private static void ShowGuest(Zoo zoo, string name)
        {
            string guestName = ConsoleUtil.InitialUpper(name);
            Guest  guest     = zoo.FindGuest(guestName);

            if (guest != null)
            {
                Console.WriteLine($"The following guest was found: {guest}.");
            }
            else
            {
                Console.WriteLine("The guest could not be found.");
            }
        }
Example #13
0
        /// <summary>
        /// Adds a new animal to the zoo.
        /// </summary>
        /// <param name="zoo">The current zoo.</param>
        private static void AddAnimal(Zoo zoo)
        {
            AnimalType animalType = ConsoleUtil.ReadAnimalType();

            Animal animal = AnimalFactory.CreateAnimal(animalType, string.Empty, 0, 1, Gender.Female);

            if (animal == null)
            {
                throw new NullReferenceException("Animal could not be found.");
            }

            animal.Name   = ConsoleUtil.InitialUpper(ConsoleUtil.ReadAlphabeticValue("Name"));
            animal.Gender = ConsoleUtil.ReadGender();
            animal.Age    = ConsoleUtil.ReadIntValue("Age");
            animal.Weight = ConsoleUtil.ReadDoubleValue("Weight");

            zoo.AddAnimal(animal);

            ConsoleHelper.ShowAnimal(zoo, animal.Name);
        }
Example #14
0
        /// <summary>
        /// Directs the remove command according to its parameter.
        /// </summary>
        /// <param name="zoo">The zoo in which to remove something.</param>
        /// <param name="type">The type of what is being removed to the zoo.</param>
        /// <param name="name">The name of what is to be removed.</param>
        public static void ProcessRemoveCommand(Zoo zoo, string type, string name)
        {
            string animalName = ConsoleUtil.InitialUpper(name);
            string guestName  = ConsoleUtil.InitialUpper(name);

            switch (type)
            {
            case "animal":
                RemoveAnimal(zoo, animalName);

                break;

            case "guest":
                RemoveGuest(zoo, guestName);

                break;

            default:
                Console.WriteLine("Command only supports removing an animal.");
                break;
            }
        }
        /// <summary>
        /// Processes the show console command.
        /// </summary>
        /// <param name="zoo">The zoo containing the object to show.</param>
        /// <param name="type">The type of object to show.</param>
        /// <param name="name">The name of the object to show.</param>
        public static void ProcessRemoveCommand(Zoo zoo, string type, string name)
        {
            string uppercaseName = ConsoleUtil.InitialUpper(name);

            switch (type)
            {
            case "animal":
                ConsoleHelper.RemoveAnimal(zoo, uppercaseName);

                break;

            case "guest":
                ConsoleHelper.RemoveGuest(zoo, uppercaseName);

                break;

            default:
                Console.WriteLine("Unknown type. Only animals and guests can be removed.");

                break;
            }
        }
        /// <summary>
        /// Adds a new animal to the zoo.
        /// </summary>
        /// <param name="zoo">The current zoo.</param>
        private static void AddAnimal(Zoo zoo)
        {
            bool success = false;

            AnimalType animalType = ConsoleUtil.ReadAnimalType();

            Animal animal = AnimalFactory.CreateAnimal(animalType, string.Empty, 0, 1, Gender.Female);

            if (animal == null)
            {
                throw new NullReferenceException("Animal could not be found.");
            }

            while (!success)
            {
                try
                {
                    string name = ConsoleUtil.ReadAlphabeticValue("Name");

                    animal.Name = ConsoleUtil.InitialUpper(name);

                    success = true;
                }
                catch (ArgumentException e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            success = false;

            while (!success)
            {
                try
                {
                    animal.Gender = ConsoleUtil.ReadGender();

                    success = true;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            success = false;

            while (!success)
            {
                try
                {
                    int age = ConsoleUtil.ReadIntValue("Age");

                    animal.Age = age;
                    success    = true;
                }
                catch (ArgumentOutOfRangeException e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            success = false;

            while (!success)
            {
                try
                {
                    double weight = ConsoleUtil.ReadDoubleValue("Weight");

                    animal.Weight = weight;
                    success       = true;
                }
                catch (ArgumentOutOfRangeException e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            zoo.AddAnimal(animal);

            ConsoleHelper.ShowAnimal(zoo, animal.Name);
        }
        /// <summary>
        /// Adds a new guest to the zoo.
        /// </summary>
        /// <param name="zoo">The current zoo.</param>
        private static void AddGuest(Zoo zoo)
        {
            bool success = false;

            Guest guest = new Guest(string.Empty, 0, WalletColor.Black, 0m, Gender.Female, new Account());

            if (guest == null)
            {
                throw new NullReferenceException("Guest could not be found.");
            }

            while (!success)
            {
                try
                {
                    string name = ConsoleUtil.ReadAlphabeticValue("Name");

                    guest.Name = ConsoleUtil.InitialUpper(name);
                    success    = true;
                }
                catch (ArgumentException e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            success = false;

            while (!success)
            {
                try
                {
                    guest.Gender = ConsoleUtil.ReadGender();
                    success      = true;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            success = false;

            while (!success)
            {
                try
                {
                    int age = ConsoleUtil.ReadIntValue("Age");

                    guest.Age = age;
                    success   = true;
                }
                catch (ArgumentOutOfRangeException e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            success = false;

            while (!success)
            {
                try
                {
                    double moneyBalance = ConsoleUtil.ReadDoubleValue("Money balance");

                    guest.Wallet.AddMoney((decimal)moneyBalance);
                    success = true;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            success = false;

            while (!success)
            {
                try
                {
                    guest.Wallet.Color = ConsoleUtil.ReadWalletColor();
                    success            = true;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            success = false;

            while (!success)
            {
                try
                {
                    double moneyBalance = ConsoleUtil.ReadDoubleValue("Checking account money balance");

                    guest.CheckingAccount.AddMoney((decimal)moneyBalance);
                    success = true;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            Ticket ticket = zoo.SellTicket(guest);

            zoo.AddGuest(guest, ticket);

            ConsoleHelper.ShowGuest(zoo, guest.Name);
        }
Example #18
0
        /// <summary>
        /// Adds the animal.
        /// </summary>
        /// <param name="zoo"> The zoo being added.</param>
        private static void AddAnimal(Zoo zoo)
        {
            // Creates a dingo with all of the inputted values.
            Animal animal = new Dingo("Joey", 43, 344, Gender.Male);

            bool success = false;

            AnimalType animalType = ConsoleUtil.ReadAnimalType();

            animal = AnimalFactory.CreateAnimal(animalType, "null", 1, 1, Gender.Male);

            // Sets the name for the animal.
            while (!success)
            {
                try
                {
                    // Gets the name and makes it upper case.

                    animal.Name = ConsoleUtil.ReadAlphabeticValue("Name");
                    animal.Name = ConsoleUtil.InitialUpper(animal.Name);

                    success = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Value must only contain letters and spaces.");
                }
            }

            success = false;

            // Sets the gender for the animal.
            while (!success)
            {
                try
                {
                    animal.Gender = ConsoleUtil.ReadGender();

                    success = true;
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }

            success = false;

            // Sets the age for the animal.
            while (!success)
            {
                try
                {
                    animal.Age = ConsoleUtil.ReadIntValue("Age");

                    success = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Value must be between 0 and 100.");
                }
            }

            success = false;

            // Sets the weight for the animal.
            while (!success)
            {
                try
                {
                    animal.Weight = ConsoleUtil.ReadDoubleValue("Weight");

                    success = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Value must be between 0 and 1000.");
                }
            }

            zoo.AddAnimal(animal);

            ShowAnimal(zoo, animal.Name);
        }
Example #19
0
        /// <summary>
        /// Adds the guest into the zoo.
        /// </summary>
        /// <param name="zoo"> The zoo that will have the guest.</param>
        public static void AddGuest(Zoo zoo)
        {
            Account account = new Account();

            Wallet wallet = new Wallet(WalletColor.Black);

            Guest guest = new Guest("Bro", 455, 0m, WalletColor.Black, Gender.Female, account);

            bool success = false;

            // Sets the name for the guest.
            while (!success)
            {
                try
                {
                    // Gets the name and makes it upper case.
                    guest.Name = ConsoleUtil.ReadAlphabeticValue("Name");
                    guest.Name = ConsoleUtil.InitialUpper(guest.Name);

                    success = true;
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }

            success = false;

            // Sets the gender for the guest.
            while (!success)
            {
                try
                {
                    guest.Gender = ConsoleUtil.ReadGender();

                    success = true;
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }

            success = false;

            // Sets the age for the guest.
            while (!success)
            {
                try
                {
                    guest.Age = ConsoleUtil.ReadIntValue("Age");

                    success = true;
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }

            success = false;

            // Sets the wallets money balance for the guest.
            while (!success)
            {
                try
                {
                    // Cast double into a decimal.
                    decimal amount = (decimal)ConsoleUtil.ReadDoubleValue("amount");

                    // Add the value inot the wallet.
                    guest.Wallet.AddMoney(amount);

                    success = true;
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }

            success = false;

            // Sets the wallets color for the guest.
            while (!success)
            {
                try
                {
                    wallet.WalletColor = ConsoleUtil.ReadWalletColor();

                    success = true;
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }

            success = false;

            // Sets the account's money balance for the guest.
            while (!success)
            {
                try
                {
                    // Cast double into a decimal.
                    decimal checking = (decimal)ConsoleUtil.ReadDoubleValue("checking");

                    // Add the value inot the wallet.
                    guest.CheckingAccount.AddMoney(checking);

                    success = true;
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }

            // Sells the guest a ticket if they have enough money, then adds them to the zoo.
            zoo.AddGuest(guest, zoo.SellTicket(guest));

            // Shows the guest on the screen.
            ShowGuest(zoo, guest.Name);
        }
Example #20
0
        /// <summary>
        /// Adds an animal to the zoo.
        /// </summary>
        /// <param name="zoo">The zoo in which to add an animal.</param>
        private static void AddAnimal(Zoo zoo)
        {
            // Reads the animal type from the console.
            AnimalType readAnimal = ConsoleUtil.ReadAnimalType();

            // Creates the entered animal type.
            Animal animal = AnimalFactory.CreateAnimal(readAnimal, "Max", 2, 78, Gender.Female) as Animal;

            // Prompt for animal name.
            bool nameSuccess = false;

            while (!nameSuccess)
            {
                try
                {
                    string animalName = ConsoleUtil.ReadAlphabeticValue("Name");
                    animal.Name = ConsoleUtil.InitialUpper(animalName);

                    nameSuccess = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            // prompt for animal gender.
            bool genderSuccess = false;

            while (!genderSuccess)
            {
                try
                {
                    animal.Gender = ConsoleUtil.ReadGender();

                    genderSuccess = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            // Prompt for animal age.
            bool ageSuccess = false;

            while (!ageSuccess)
            {
                try
                {
                    animal.Age = ConsoleUtil.ReadIntValue("Age");

                    ageSuccess = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            // Prompt for animal weight.
            bool weightSuccess = false;

            while (!weightSuccess)
            {
                try
                {
                    animal.Weight = ConsoleUtil.ReadDoubleValue("Weight");

                    weightSuccess = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            // Add the newly created animal to the list.
            zoo.AddAnimal(animal);

            // Show the new animal.
            ShowAnimal(zoo, animal.Name);
        }
Example #21
0
        /// <summary>
        /// Adds a guest to the zoo.
        /// </summary>
        /// <param name="zoo">The zoo in which to add a guest.</param>
        private static void AddGuest(Zoo zoo)
        {
            // Create a new guest.
            Guest guest = new Guest("Joe", 36, 0, WalletColor.Brown, Gender.Male, new Account());

            // Prompt for guest name.
            bool nameSuccess = false;

            while (!nameSuccess)
            {
                try
                {
                    string guestName = ConsoleUtil.ReadAlphabeticValue("Name");
                    guest.Name = ConsoleUtil.InitialUpper(guestName);

                    nameSuccess = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            // prompt for guest gender.
            bool genderSuccess = false;

            while (!genderSuccess)
            {
                try
                {
                    guest.Gender = ConsoleUtil.ReadGender();

                    genderSuccess = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            // Prompt for guest age.
            bool ageSuccess = false;

            while (!ageSuccess)
            {
                try
                {
                    guest.Age = ConsoleUtil.ReadIntValue("Age");

                    ageSuccess = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            // Prompt for guest wallet money balance.
            bool walletSuccess = false;

            // CREATED DECIMAL METHOD IN UTIL.
            while (!walletSuccess)
            {
                try
                {
                    guest.Wallet.AddMoney(ConsoleUtil.ReadDecimalValue("Wallet Money Balance"));

                    walletSuccess = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            // Prompt for guest wallet color.
            bool walletColorSuccess = false;

            while (!walletColorSuccess)
            {
                try
                {
                    WalletColor walletColor = ConsoleUtil.ReadWalletColor();

                    walletColorSuccess = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            // Prompt for guest checking account balance.
            bool accountSuccess = false;

            while (!accountSuccess)
            {
                try
                {
                    guest.CheckingAccount.AddMoney(ConsoleUtil.ReadDecimalValue("Account Balance"));

                    accountSuccess = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            // Add the newly created guest to the list after selling them a ticket and a waterbottle. This will subtract $18.00 from the entered money balance.
            zoo.AddGuest(guest, zoo.SellTicket(guest));

            // Show the new animal.
            ShowGuest(zoo, guest.Name);
        }