static void Main(string[] args) { Animals animal = new Animals("Zebra", 50, 50); animal.Eat(); animal.Drink(); animal.Play(); //Console.WriteLine(animal.Thirst); Console.ReadLine(); }
public static void Main(string[] args) { string input = string.Empty; while (true) { string type = Console.ReadLine(); if (type == "Beast!") { break; } input = Console.ReadLine(); string[] line = input.Split(); Animals animal = null; try { switch (type) { case "Dog": animal = new Dog(line[0], int.Parse(line[1]), line[2]); break; case "Cat": animal = new Cat(line[0], int.Parse(line[1]), line[2]); break; case "Frog": animal = new Frog(line[0], int.Parse(line[1]), line[2]); break; case "Kitten": animal = new Kitten(line[0], int.Parse(line[1])); break; case "Tomcat": animal = new Tomcat(line[0], int.Parse(line[1])); break; } } catch (ArgumentException ae) { Console.WriteLine(ae.Message); } Console.WriteLine(animal.ToString()); } }
public bool Swim(Animals animal) { //Animals animal = new Animals(); bool canSwim; if (animal.animalType.ToString() == "fish" && animal.habitat.ToString() == "ocean") //|| animal.species_name == "bear" || animal.species_name == "seal") { canSwim = true; Console.WriteLine("This animal can swim! Swimming now!"); return(canSwim); } if (animal.habitat.ToString() == "ocean" && animal.animalType.ToString() == "mammal") //dolphin, whale, seal { canSwim = true; Console.WriteLine("This animal can swim! Swimming now!"); return(canSwim); } //there are probably a bunch of animals who can swim, so what if I just ask if the animal is observed swimming or something...I don't know... Console.WriteLine("There are many animals who can swim. Is the animal swimming now or looks like she/he wants to? : "); String probablySwim; probablySwim = Convert.ToString(Console.ReadLine()); if (probablySwim == "yes" || probablySwim == "Yes") { Console.WriteLine(); Console.WriteLine("This animal can probably swim. Wait and see..."); canSwim = true; return(canSwim); } else { Console.WriteLine(); Console.WriteLine("More information on animal needed, then. "); canSwim = false; //return canSwim; } canSwim = false; return(canSwim); }
public static double AverageAge(Animals[] array) { if (array.Length == 0) { throw new ArgumentException("There is no data for such animals"); } else if (array.Length == 1) { return array[0].Age; } double sum = 0; foreach (var animal in array) { sum += animal.age; } return sum / array.Length; }
//methods and functions, at least two public Animals DisplayAnimal(Animals animal) { //Animals animal = new Animals(species_name, animalType, name, habitat, typeOfEater, filmed, whenActive); Console.WriteLine("The current data on this animal is: "); Console.WriteLine(); Console.WriteLine("Species: {0}", species_name); Console.WriteLine(); Console.WriteLine("Animal Type: {0}", animalType.ToString()); Console.WriteLine(); //Console.WriteLine("Name: {0}", name); //Console.WriteLine(); Console.WriteLine("Habitat: {0}", habitat.ToString()); Console.WriteLine(); Console.WriteLine("Type of eater: {0}", typeOfEater.ToString()); Console.WriteLine(); Console.WriteLine("Filmed: {0}", filmed); Console.WriteLine(); Console.WriteLine("When active: {0}", whenActive.ToString()); Console.WriteLine(); return(animal); }
public bool filmAnimal(Animals animal) { //we want to film animals and the stuff they do, so we find them first in order to do so /*bool found = true; * * if(!found) * { * //look for animal * Console.WriteLine("Searching for animal to film..."); * * }*/ //Animals animal = new Animals(); Video video; Console.WriteLine("What will be the title of this video (type rough draft if uncertain): "); video.title = Convert.ToString(Console.ReadLine()); Console.WriteLine(); Console.WriteLine("Who is(are) the filmmaker(s)? : "); video.filmmakers = Convert.ToString(Console.ReadLine()); Console.WriteLine(); Console.Write("What one animal by species name would you like to film? (Type something like gazelle, giraffe, etc. : "); String speciesName; speciesName = Convert.ToString(Console.ReadLine()); animal.species_name = speciesName; video.animalsFilmed = animal.species_name; Console.WriteLine(); //Console.WriteLine("Okay, let's search for {0}...", animal.species_name); //I wonder if I need to ask for the type of the animal and everything else...I guess I could ask for where the animal will be filmed and probably when... //to identify the animal for the time being, let's ask for the name of the animal /*Console.WriteLine("What is the name of the animal to film? : "); * animal.name = Convert.ToString(animal.name);*/ Console.WriteLine("Where are we filming this animal? : "); video.location = Convert.ToString(Console.ReadLine()); Console.WriteLine(); Console.WriteLine("In what natural environment are we filming this animal? : "); /*String habitat; * habitat = Convert.ToString(Console.ReadLine()); * animal.setHabitat(habitat);*/ //animal.habitat.ToString() = habitat; // Colors colorValue = (Colors) Enum.Parse(typeof(Colors), colorString); String habitatValue; habitatValue = Convert.ToString(Console.ReadLine()); //Parse(habitats, habitat); habitats habitat = (habitats)Enum.Parse(typeof(habitats), habitatValue); animal.setHabitat(habitat); video.environment = habitatValue; Console.WriteLine(); Console.WriteLine("When are we filming this animal? : "); /*String timeOfDay; * timeOfDay = Convert.ToString(Console.ReadLine()); //morning, afternoon, night*/ video.date = Convert.ToString(Console.ReadLine()); Console.WriteLine(); Console.WriteLine("How long will the video of this animal be? : "); video.duration = Convert.ToString(Console.ReadLine()); Console.WriteLine(); Console.WriteLine("Off we go!\n"); animal.filmed = true; Console.WriteLine(); Console.WriteLine("Animal has been filmed.\n"); return(animal.filmed); }
static void Main(String[] args) { /* Animals class needs at least two constructors, a struct, at least 5 member variables, methods or functions, private variables, getter and setter, and instances of the class. * Main method has to be in different class (other file). Use enum for the classification of the animal*/ //Animals elephant = new Animals(elephant, mammal, Rose, grassland, herbivore, false, diurnal); //so it's like we've come across an animal, we are observing her or him, and then we are deciding to film her/him Animals animal = new Animals(); Console.WriteLine("What is the species name of the animal (elephant, duck, or what)? : "); animal.setSpeciesName(Convert.ToString(Console.ReadLine())); Console.WriteLine(); Console.WriteLine("Animal type (mammal, bird, reptile, etc.)? : "); String theType; theType = Convert.ToString(Console.ReadLine()); Animals.animalTypes animalType = (Animals.animalTypes)Enum.Parse(typeof(Animals.animalTypes), theType); animal.setAnimalType(animalType); //habitats habitat = (habitats)Enum.Parse(typeof(habitats), habitatValue); Console.WriteLine(); /*Console.WriteLine("Name of animal? : "); * animal.setName(Convert.ToString(Console.ReadLine())); * * Console.WriteLine();*/ Console.WriteLine("Habitat? : "); String theHabitat; theHabitat = Convert.ToString(Console.ReadLine()); Animals.habitats habitat = (Animals.habitats)Enum.Parse(typeof(Animals.habitats), theHabitat); animal.setHabitat(habitat); Console.WriteLine(); Console.WriteLine("What type of eater is this animal? : "); String eatingType; eatingType = Convert.ToString(Console.ReadLine()); Animals.Eaters typeOfEater = (Animals.Eaters)Enum.Parse(typeof(Animals.Eaters), eatingType); animal.setTypeOfEater(typeOfEater); Console.WriteLine(); Console.WriteLine("Has this animal been filmed yet? : "); String isFilmed; isFilmed = Convert.ToString(Console.ReadLine()); if (isFilmed == "yes" || isFilmed == "Yes") { animal.setFilmed(true); } else { animal.setFilmed(false); } Console.WriteLine(); Console.WriteLine("Is this creature diurnal, nocturnal, crepuscular, or cathemeral? : "); String activityTimeType; activityTimeType = Convert.ToString(Console.ReadLine()); //habitats habitat = (habitats)Enum.Parse(typeof(habitats), habitatValue); Animals.active whenActive = (Animals.active)Enum.Parse(typeof(Animals.active), activityTimeType); animal.setWhenActive(whenActive); Console.WriteLine("-------------------------------------------------------------"); Console.WriteLine(); //display the new animal animal.DisplayAnimal(animal); Console.WriteLine(); animal.Fly(animal); animal.Swim(animal); animal.filmAnimal(animal); Console.ReadKey(); }