Question: Edit: What additional info is needed? Challenge: Pets Description: Create and test Pet, Dog, and Cat classes in C# where Dog and Cat are subclasses







Edit: What additional info is needed?
Challenge: Pets Description: Create and test Pet, Dog, and Cat classes in C# where Dog and Cat are subclasses of Pet. Purpose: The purpose of this challenge is to provide experience with creating and using classes, subclasses, and object instances in C#. Requirements: Project Name: Pets Target Platform: .NET Core Console Application Programming Language: C# Create a program in C# called Pets that contains Pet, Dog , and Cat classes where Dog and Cat are subclasses of Pet. The classes are to be tested using the test code provided in this document. Pet Class The Pet class is to be created in a file called Pet.cs. The Pet class is to have four public properties: type, name , owner , and weight. The type property is to be a string that specifies the type of pet such as "dog", "cat", "bird", etc. The name property is to be a string that specifies the name of the pet. The owner property is to be a string that is the name of the owner of the pet. And, the weight property is to be a double that specifies the weight of the pet in pounds. The Pet class is to have a constructor that accepts type, name, owner, and weight to initialize a new instance of a Pet and sets its properties. The Pet class is to have a public method (function) called getTago that returns a string that is the string "If lost, call " concatenated with the name of the pet's owner. So, for example, if owner is Karen", getTag() is to return "If lost, call Karen". To test the Pet class, the following code can be placed in the Main method of the C# program. Pet pet1 = new Pet("dog", "Shadow", "Jose", 42.6); Console.WriteLine("Name: " + pet1.name); Console.WriteLine("Weight: " + pet1.weight); Console.WriteLine(pet1.getTag()); When the above code is run, the following output is generated. Name: Shadow Weight: 42.6 If lost, call Jose Dog Class The Dog class is to be created in a file called Dog.cs and is to be a subclass of the Pet class. The Dog class has no additional new properties beyond what the Pet class supplies. Therefore, a Dog class has the Pet properties that it inherits: type, name , owner , and weight. The Dog class is to have a constructor that accepts name , owner , and weight to initialize a new instance of a Dog and set its properties. To do this, the Dog class constructor is to call the superclass (Pet) constructor using basel) c. When the superclass constructor is called, the type is to be automatically set to "dog". The Dog class inherits the getTag method. getTag is available to Dog because it inherited it from the Pet class. The Dog class is to have a public method called bark that returns a string with a quantity of "bark!" concatenated together. The number of "bark!" in the returned string is based on a int parameter of bark called count that specifies the quantity. The following is the declaration of the bark method. public string bark(int count) // put code to generate string here } If count is 4, the output of bark would be: bark!bark!bark!bark! To test the Dog class, the following code can be placed in the Main method of the C# program. Dog dog1 = new Dog("Daisy", "Kent", 23.4); Console.WriteLine("Name: + dog1.name); Console.WriteLine("Weight: " + dog1.weight); Console.WriteLine(dog1.getTago); Console.WriteLine(dog1.bark(4)); When the above code is run, the following output is generated. Name: Daisy Weight: 23.4 If lost, call Kent bark!bark!bark!bark! Cat Class The Cat class is to be created in a file called Cat.cs and is to be a subclass of the Pet class. The Cat class has no additional new properties beyond what the Pet class supplies. Therefore, a Cat class has the Pet properties that it inherits: type), name , owner , and weight). The Cat class is to have a constructor that accepts name , owner , and weight to initialize a new instance of a Cat and set its properties. To do this, the Cat class constructor is to call the superclass (Pet) constructor using base() e. When the superclass constructor is called, the type is to be automatically set to "cat". The Cat class inherits the getTag method. getTag is available to Cat because it inherited it from the Pet class. The Cat class is to have a public method called meow that returns a string with a quantity of "meow." concatenated together. The number of "meow." in the returned string is based on a int parameter of meow called count that specifies the quantity. The following is the declaration of the meow method. public string meow(int count) { // put code to generate string here } If count is 3, the output of meow would be: meow.meow.meow. To test the Cat class, the following code can be placed in the Main method of the C# program. Cat cat1 = new Cat("Simba", "Maria", 5.2); Console.WriteLine("Name: + cat1.name); Console.WriteLine("Weight: " + cat1.weight); Console.WriteLine(cat1.getTag(); Console.WriteLine(cat1.meow(3)); When the above code is run, the following output is generated. Name: Simba Weight: 5.2 If lost, call Maria meow.meow.meow. Working on Challenge The best way to complete this challenge is to first create the Pet class, get it working, and test it. Then, implement the Dog class as a subclass of Pet, get it working, and test it. Finally, implement the Cat class as a subclass of Pet, get it working, and test it. Don't try to get all three classes implemented, working, and tested at once. Do them one at a time starting with Pet. The following screen capture shows the test code that is placed in Main once all three classes are implemented. Your submitted program is to use the same test code. (Note: the following screen captures are from Visual Studio Community IDE. You are using Visual Studio Code in this course. The code is the same...the user interface looks different.) Debug Default Visual Studio Co...nity 2017 for Mac Qu Press ''to sea Solution Dog.cs Cat.cs Program.cs Pet.cs Program M Main(string[] args) using System; Toolbox Pets Pets Dependencies 0 Cat.cs 0 Dog.cs Pet.cs Program.cs 3 4 5 namespace Pets { class Program { static void Main(string[] args) { Pet pet1 = new Pet("dog", "Shadow", "Jose", 42.6); Console.WriteLine("Name:" + pet1.name); Console.WriteLine("Weight: " + pet1.weight); Console.WriteLine(pet1.getTag()); Properties Document Outline Unit Tests Console.WriteLine(""); 16 17 18 19 20 21 22 Dog dog1 = new Dog("Daisy", "Kent", 23.4); Console.WriteLine("Name:" + dog1.name); Console.WriteLine("Weight: " + dog1.weight); Console.WriteLine(dog1.getTag()); Console.WriteLine(dog1. bark(4)); Console.WriteLine(""); 24 26 Cat cat1 = new Cat("Simba", "Maria", 5.2); Console.WriteLine("Name: + cat1.name); Console.WriteLine("Weight: " + cat1.weight); Console.WriteLine(cat1.getTag(); Console.WriteLine(cat1. meow (3)); } } Errors Tasks Application Output - Pets Package Console Pets Main The Pets project contains four code files as shown below: Program.cs, Pet.cs, Dog.cs, and Cat.cs. Debug Solution Pets Pets Dependencies 0 Cat.cs O Dog.cs Pet.cs O Program.cs Pets Files The following is the output displayed in the Console when the completed app is run. dale - Pets.dll bash -c clear; cd "/Applications/Visual Studio.app/Contents/Re... Name: Shadow Weight: 42.6 If lost, call Jose Name: Daisy Weight: 23.4 If lost, call Kent bark!bark!bark!bark! Name: Simba Weight: 5.2 If lost, call Maria meow.meow.meow. Press any key to continue
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
