C# Inheritance Assignment: Implementing Cat, Dog, and Rabbit Classes

Verified

Added on  2019/09/16

|2
|447
|340
Practical Assignment
AI Summary
This assignment involves implementing inheritance in C# using the provided CatExampleWithInheritance application. The task includes modifying the Cat class to include a “HasFlees()” method and overriding it in the BreedCat class. Additionally, the assignment requires implementing specific images for each cat, including Fluffy, Jassie, and moggies, with an option for breed-specific images. Furthermore, the assignment extends to creating a Pet class, and Dog and Rabbit classes that inherit from it. An IAnimal interface is to be implemented by both Pet and WildAnimal classes, and the animals are to be sorted by species. This practical assignment aims to reinforce understanding of object-oriented programming principles such as inheritance, polymorphism, and interfaces through hands-on coding and modification of existing code.
Document Page
LAB: Inheritance
Part A – playing with code.
1. Save the CatExampleWithInheritance application available on the course
page for this week in a trusted location and study the code. Comment the c#
code (all the main lines, especially the ones linked to inheritance)
2. Save the InterfaceExample application available on the course page for this
week in a trusted location and study the code Comment the c# code (all the
main lines, especially the ones linked to inheritance)
Part B - Change the CatExampleWithInheritance
application that you downloaded
EXERCISE 1: change the necessary code in the following way:
1. In the Cat class add a method called “HasFlees()” which should return a
Boolean. This method should be seen only by the base Cat class and its
children. The method should return true value. Change the Talk() method so
it would say if the cat has flees.
2. In the BreedCat class override the method “HasFlees()” and make it return
false
EXERCISE 2
1. You should have noticed that showing cat images is not implemented in a
consistent way. Change the code in such way that every cat has a specific
image in the following way:
In the class Cat have a field “imageString” of type string.
Change the code in such way that Fluffy and Jassie are instantiated
with the correct images (use a particular cat image for each) .
Change the code in such way that all new cats (moggies) will have a
particular image of your choice
Change the code in such way that for the breed cats the user can
choose a breed from a drop down list and, according to the selected
breed, a specified image is displayed
Hint: you can store the breeds and the images’ names in
arrays, generic lists or a table in the database
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
For the brave : Exercise 3
Change the above application so the Cat inherits from a class Pet. Also create a
class Dog and Rabbit that inherit from the pet. Your main UI page should allow you
to add all sorts of pets. These should be added to a List and another UI page should
display all the pets you created.
Have the class Pet implement an interface called IAnimal.
Have another class WildAnimal implement the interface called IAnimal.
Both Wild animals and pets have species.
Sort all the animals by their species (you may need to implement the IComparable)
chevron_up_icon
1 out of 2
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]