This program keeps track of an inventory of animals and their attributes in C# through a graphical user interface. It utilizes Object Oriented Programming concepts such as inheritance, encapsulation (exception handling), abstraction, and polymorphism.
The base class, called Animal, has private string fields for name, breed, color, and an array of vaccination record objects. There are public properties and an overloaded constructor in this class. To validate this data, an exception class is used to determine if there is invalid input. In each property of the Animal base class, the setter method invokes a function that checks each character of the input value to ensure it contains only letters. If it encounters a character that is not a letter, it throws an exception, passing an error message indicating which data field caused the exception. In main, a try and catch block is used. The program tries to create a dog or horse object, and if an exception is thrown, the program will send an error message and the object will not be created. Furthermore, there is a protected virtual display method that will concatenate a string of the data mentioned and return it. There is also a public access display method that will access the protected display method.
There are two child classes: Dog and Horse. In each class, there are different fields that will inherit from the base class. In the dog class, there are private fields for birth date, weight, and training. In the horse class, there are private fields for registered name, size, and year of birth. In each class, there are public properties and an overloaded constructor that inherits from the base class. For each data field, there are custom exception classes to validate the data. For example, the birth date field ensure it is in the form of MM/DD/YY and is a valid date. Moreover, there are protected override display methods that will override the original display method in the base class.
In the last class (vaccination records), there are private fields for vaccination code, date, and person. It includes public properties and an overloaded constructor. This class is used to create an array of vaccination record objects.
In the main program, a list of animal objects is created. A list of strings is also declared, which is used to display the current inventory of objects. When the program starts, all of the text fields for horses and dogs are disabled until the user chooses which animal to pick (this is achieved through a radio button). When the user decides to submit an animal, the submit method is called, and the program gets and parses input from the user. A decision structure is used to determine which animal the user is inputting, and after going through data validation (via try and catch blocks), a new animal object is created and added to the animal list. The form is then cleared, and the current inventory of data is displayed in a rich text box. This is achieved by utilizing string builder. Once an object is created, the new data is concatenated into a string by calling the access display method from the animal object. This data is added to the array of strings, and this array is concatenated into a single string. This is how the data is able to appear in the rich text box.