Purpose
This project is designed to teach you how to manipulate exceptions, properties, and arrays. It reinforces your understanding of class design and implementation while introducing the handling of exceptions.
Challenge
In short
Develop a class that helps gather data about temperature statistics. Your class will allow to compute the mean, median and (optionally) mode of arrays of temperatures (in Fahrenheit), and raise exceptions if the data is incorrectly entered.
In more details
- Your goal is to design and implement a
TempStats
class containing two attributes and several methods (some of which may and should be implemented using properties). - You must develop a
Program
class with aMain
method to test yourTempStats
class, but note that thisProgram
class will not be part of your grade. - An object in your
TempStats
must hold two attributes: a (string
) description, and an array of temperatures (in Fahrenheit). The description must be implemented using automatic properties. - The array of temperatures must be sorted: if at any point during creation or later modification the array were to become not sorted, your class should throw an exception.
- The temperatures in the array must be between -128.6 and 134.1 (the lowest and highest temperatures ever recorded on Earth): if at any point during creation or later modification of the array the temperatures were to exceed that range, your class should throw an exception.
- Finally, your class should have two methods, one to compute the mean of the values in the array, and one to compute the median. Both methods can be implemented as properties.
Submission
Please, follow our guideline on project submission. In particular, make sure you write your name and the date in a delimited comment at the beginning of your file.
Example
Here is an example of a Program.cs
Main
method:
Executing it with a properly implemented TempStats
class should give
something along the lines of:
Note that it is ok if you cannot reproduce this output exactly.
Bonuses
- Implement a method to display the values and the description nicely.
- Implement a method to display the values converted to Celcius nicely.
- Accept arrays sorted in increasing or decreasing order. That is, the
array
3.5, -10, -15
should be accepted. - Implement a method (or property) to compute the mode of the temperatures. Note that the mode is not always unique: in that case, an exception should be raised.