CSCI 1301 – Lab 22

Clément Aubert

October 22, 2019

A Class for Chemical Elements (static members)

You will study and modify a class for chemical elements (consult https://en.wikipedia.org/wiki/List_of_chemical_elements#List for a complete list).

Reading

Download ChemElemProject, extract the project, open it in VS, compile and execute it. Now read the code in “ChemElem.cs” and “Program.cs”.

The class definition “ChemElem.cs” contains:

The application program “Program.cs” performs one simple conversion from Kelvin to Celsius, using data given by the user, create and display a ChemElem object (implicitely calling the ToString method).

Modifying

Do the following:

  1. In “ChemElem.cs”, write getters and setters for all attributes
  2. In “Program.cs”, create a second object using our custom constructor, and display the value of its attributes using the getters you previoulsy defined.
  3. In “ChemElem.cs”, write a no-args constructor.
  4. In “Program.cs”, create an object using the no-args constructor, and set its values using the setters your previously defined.
  5. In “Program.cs”, display on the screen the string returned by the ToString method when it is called by the object you created at the previous step.
  6. In “Program.cs”, try calling the FromKelvinToCelsius method with one of your object, for instance using hydrogen.FromKelvinToCelsius(34). What happens?
  7. Still in “Program.cs”, try calling the MeltingInCelsius method with the class, for instance using ChemElem.MeltingInCelsius();. What happens?

Enhancing

We now want to significantly improve this class, by adding

  1. An attribute for the boilling point,
  2. All the tools needed to display the information in Fahrenheit degree, in addition to Celsius and Kelvin.

You may want to comment part, of all of your “Program.cs” file, before starting to change your class.

You should test all of those modifications in your “Program.cs” file as you implement them. Use relevant data, test your program, and make sure the behaviour is the expected behaviour.