Absolute Zero

Line: Object Line
Type: Exercise
You should have completed: Vector Class This topic leads to: Fractions

Summary

This exercise will have you thinking more about Classes, Objects and their Methods and Properties. If you have done the 'Temperature Conversion' exercise, it will give you a head start.

Task

  1. Create a new C# Console project in Visual Studio.
    OR
    Load up your 'Temperature Conversion' exercise if you have access to it.
  2. Right click the Project name found in the Solution Explorer on the right hand side of Visual Studio, select 'Add', select 'New item...' and finally select 'Class' from the list. Give it the name 'TemperatureClass.cs' and click 'Add'.
  3. Add three properties (Celsius, Fahrenheit, Kelvin) and several methods to your 'TemperatureClass' Class. The methods should allow you to perform calculations from any of the properties into any other (Celsius <-> Fahrenheit, Celsius <-> Kelvin, Fahrenheit <-> Kelvin). Test these out in Main().
  4. Create two Constructor Methods in your 'TemperatureClass' Class as shown below. Try creating a TemperatureClass Object in Main() with a parameter (e.g.: 100.25), then try it without a parameter.
    code snippet

Questions

  1. How would you change your program to not crash if no parameter is passed to the 'TemperatureClass' Constructor Method?
    Hint 1: You should start your investigation in 'Main()'.
    Hint 2: Look at the 'try'/'catch' statements.