/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }