static void Main() { /* Objects and Classes*/ Animal dogAnimal = new Animal(); // You create an instance of the Class 'Animal' with the empty constructor dogAnimal.Name = "Dog"; //You set the property Name to Dog Animal catAnimal = new Animal("Cat"); // You create an instance of the Class 'Animal' with a parameter for Name Console.WriteLine("Dog's animal name is " + dogAnimal.Name); Console.WriteLine("Cats's animal name is " + catAnimal.Name); //Two vars can reference the same Object Animal bearOne = new Animal("Bear"); Animal bearTwo = bearOne; Console.WriteLine("bearTwo name is " + bearTwo.Name); //One var can reference different Objects (at different time) Animal lion = new Animal("Tiger"); lion = new Animal("Lion"); Console.WriteLine("lion name is " + lion.Name); /* Inheritance*/ Animal dog = new Dog("Dog"); Console.WriteLine("Dog's name is " + dog.Name); Animal cat = new Cat("Cat"); Console.WriteLine("Cat's name is " + cat.Name); Console.WriteLine("Cat's, which are Animals, breathe like this "); cat.Breathe(); //method defined for all Animals Console.ReadLine(); }
static void Main() { Dog myDog = new Dog("Moby", 2, 0.4); Console.WriteLine("My dog " + myDog.name + " is " + myDog.age + " year(s) old " + " and it has length: " + myDog.length + " m."); }
static void Main(string[] args) { //use Human class Human oana = new Human(); //Oana is the object, human is the class oana.Eyes = 2; // setter oana.Name = "Oana"; // setter oana.SaySomething(); oana.Yell(); var myName = oana.Name; // getter Console.WriteLine($"myName = {myName}"); // Another Human Human otherHuman = new Human(); otherHuman.CanYell = true; otherHuman.SaySomething(); otherHuman.Yell(); // Third Human Human thirdHuman = new Human(2, "Scoala Informala"); thirdHuman.SaySomething(); //First dog Dog firstDog = new Dog(4, "Bobita"); //new Dog() firstDog.Bark(); Dog secondDog = new Dog(); secondDog.Bark(); secondDog.SaySomething(); //First car Car firstCar = new Car(); firstCar.Name = "Ford"; firstCar.Weels = 4; firstCar.NumberOfDoors = 6; firstCar.SayCarName(); Console.WriteLine($"{firstCar.Name} has {firstCar.Weels} wheels and {firstCar.NumberOfDoors} doors"); //Print const and readonly Console.WriteLine($"dateOfBirth = {firstCar.dateOfBirth}"); //third dog Dog thirdDog = new Dog() { Legs = 4, Name = "Azorel" }; Console.WriteLine($"thirdDog name = {thirdDog.Name}"); Console.WriteLine(thirdDog.DogInformation); //static Console.WriteLine($"My static animal is {Animal.GetName()}"); Console.WriteLine($"My static animal is {Animal.Name}"); //structss Color color = new Color(); color.red = "Red"; Console.WriteLine($"I like color{color.red}"); //Enum Console.WriteLine($"Week Monday = {week.Monday}"); Console.WriteLine($"Week Monday = {(int)week.Monday}"); Console.WriteLine($"Week Tuesday = {(int)week.Tuesday}"); //i get Vehicle vehicle = new Vehicle(); vehicle.Name = "Ford"; vehicle.Country = "USA"; vehicle.Wheels = 4; vehicle.Price = 20000; vehicle.CreationDate = 2015; vehicle.GetCarInfo(); Console.WriteLine(vehicle.CarAge); vehicle.GetCarPrice(); //Rabbit Rabbit rabbit = new Rabbit(); rabbit.Eyes = "blue"; rabbit.Fur = "white"; rabbit.Gender = "male"; rabbit.BirthDate = 2012; rabbit.Behavior = "moves, sleeps and eats"; rabbit.Type = "mammal"; rabbit.GetRabitInfo(); Console.WriteLine(rabbit.RabbitAge); rabbit.RabbitBehavior(); }
static void Visit() { Console.WriteLine("YOU CHOSE TO VISIT THE FARM"); Console.ReadLine(); //CONSTRUCTORS Pig Napoleon = new Pig("Napoleon"); Horse Clover = new Horse("Clover"); Dog Dog = new Dog("Dog"); Pig Snowball = new Pig("Snowball"); Horse Mollie = new Horse("Mollie"); Pig Piggie = new Pig("Piggie"); Horse Horsey = new Horse("Horsey"); Cat Cat = new Cat("Cat"); Chicken Dave = new Chicken("Dave"); Pig Pig = new Pig("Pig"); Chicken Chicken = new Chicken("Chicken"); Sheep Sheep = new Sheep("Sheep"); Horse Horse = new Horse("Horse"); FarmStory.Intro(); Console.WriteLine("<Napoleon escorts you to the farm>"); Console.ReadLine(); //SOME OF THE METHODS Dog.Talk(); Cat.Meow(); Horsey.Neigh(); Horsey.Speak("Horsey"); Piggie.Oink(); Sheep sheep = new Sheep("Sheepie"); sheep.Speak("Sheepie"); sheep.Eat(); Dave.Cluck("Dave"); Console.ReadLine(); FarmStory.Scene1(); Console.ReadLine(); string input = ""; do //THESE METHODS ARE FOUND IN ANIMAL.CS { Console.WriteLine("What would you like to learn about?"); Console.WriteLine("1. The Pigs"); Console.WriteLine("2. The Horses"); Console.WriteLine("3. The Cat"); Console.WriteLine("4. The Dog"); Console.WriteLine("5. The Sheep"); Console.WriteLine("6. The Chickens"); Console.WriteLine("<When you are ready to move on, enter any other value>"); input = Console.ReadLine(); switch (input) { case "1": Piggie.GetInfo("Pigs", 4, 2, "pink"); break; case "2": Horse.GetInfo("Horses", 4, 2, "Brown"); break; case "3": Cat.GetInfo("cat", 4, 2, "black"); break; case "4": Dog.GetInfo("dog", 4, 2, "tan"); break; case "5": Dog.GetInfo("sheep", 4, 2, "white"); break; case "6": Dog.GetInfo("chickens", 2, 2, "tan"); break; default: break; } } while (input == "1" || input == "2" || input == "3" || input == "4" || input == "5" || input == "6"); Console.ReadLine(); do //THESE METHODS ARE FOUND IN ANIMAL.CS { Console.WriteLine("Who would you like to talk to?"); Console.WriteLine("1. Piggie"); Console.WriteLine("2. Horsey"); Console.WriteLine("3. The Cat"); Console.WriteLine("4. The Dog"); Console.WriteLine("<When you are ready to move on, enter any other value>"); input = Console.ReadLine(); switch (input) { case "1": Piggie.Dialogue("Piggie"); break; case "2": Horsey.Dialogue(4, 2, "Horsey"); break; case "3": Cat.Dialogue(); break; case "4": Dog.Dialogue("Dog"); break; default: break; } } while (input == "1" || input == "2" || input == "3" || input == "4"); FarmStory.Scene2(); FarmStory.EndScene(); }