INF1003F – Workshop 9
The Durban July is an annual horse meet that has been presented every year since 1897
where horses compete in a series of races. Write a C# program to handle registrations for
the race. The program must meet the following specifications:
Question 1 – Classes [40]
Create a class, Horse, to save the following information for each horse in the race:
o Name – String value representing the horse name;
o Age - Age in years (integer);
o Height - The height of the horse in hands (integer); and
o Times – An array that stores the times that the horse achieved in the last
three races in seconds (double).
The class should have the following methods:
o Horse(): Default and parameterized constructors
o double AverageTime(): A method that returns the average time of the last
three races.
o string HorseDetails(): A method that returns a string representation of the
horse in the following format:
“Name: <name>\tAge: <Age>\tHeight: <height>\t Average run: <AverageTime()>”
Create a class, July, that contains the information for all the horses in the meet:
o List<Horse> horses: A list of Horse objects for all the horses that are
participating
The class should have the following methods:
o public July: Default constructor
o public void AddHorse(Horse): A method that adds the Horse argument to
the List of horses.
o public void DisplayRoster(TextBox): A method that displays the roster for
the upcoming final race on the TextBox argument by calling the
HorseDetails() method for each horse.
o public Horse Favourite(): The horse with the best average time for the
previous races is named the favourite. Identify the favourite from the list of
horses and return it to the calling statement. Assume that each horse's time
will be unique.
, INF1003F – Workshop 9
Question 2 – Main program [10]
The main program must have the following functionality:
o Create a user interface as in the example below. The output area is a multi-
line TextBox.
o When the form loads, create a class-level (global) object of the July class.
o When the “Add” button is clicked, use the July object methods and the input
fields on the form to add a new horse to the meet roster. Display the roster
with the method in the next section.
o Write a method Display() and use the relevant methods of the July and
Horse classes to show the roster for the next race. See the figure below for
example output.
o When the “Predict next winner” button is clicked, display the favourite horse
in a MessageBox by using the appropriate methods of the July and Horse
classes.
,
,
,
The Durban July is an annual horse meet that has been presented every year since 1897
where horses compete in a series of races. Write a C# program to handle registrations for
the race. The program must meet the following specifications:
Question 1 – Classes [40]
Create a class, Horse, to save the following information for each horse in the race:
o Name – String value representing the horse name;
o Age - Age in years (integer);
o Height - The height of the horse in hands (integer); and
o Times – An array that stores the times that the horse achieved in the last
three races in seconds (double).
The class should have the following methods:
o Horse(): Default and parameterized constructors
o double AverageTime(): A method that returns the average time of the last
three races.
o string HorseDetails(): A method that returns a string representation of the
horse in the following format:
“Name: <name>\tAge: <Age>\tHeight: <height>\t Average run: <AverageTime()>”
Create a class, July, that contains the information for all the horses in the meet:
o List<Horse> horses: A list of Horse objects for all the horses that are
participating
The class should have the following methods:
o public July: Default constructor
o public void AddHorse(Horse): A method that adds the Horse argument to
the List of horses.
o public void DisplayRoster(TextBox): A method that displays the roster for
the upcoming final race on the TextBox argument by calling the
HorseDetails() method for each horse.
o public Horse Favourite(): The horse with the best average time for the
previous races is named the favourite. Identify the favourite from the list of
horses and return it to the calling statement. Assume that each horse's time
will be unique.
, INF1003F – Workshop 9
Question 2 – Main program [10]
The main program must have the following functionality:
o Create a user interface as in the example below. The output area is a multi-
line TextBox.
o When the form loads, create a class-level (global) object of the July class.
o When the “Add” button is clicked, use the July object methods and the input
fields on the form to add a new horse to the meet roster. Display the roster
with the method in the next section.
o Write a method Display() and use the relevant methods of the July and
Horse classes to show the roster for the next race. See the figure below for
example output.
o When the “Predict next winner” button is clicked, display the favourite horse
in a MessageBox by using the appropriate methods of the July and Horse
classes.
,
,
,