-
Notifications
You must be signed in to change notification settings - Fork 0
/
Element.cs
52 lines (45 loc) · 1.4 KB
/
Element.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System.Text;
namespace ChemTools {
/// <summary>
/// A chemical Element. Immutable.
/// </summary>
public class Element {
//i.e. H
public readonly string symbol;
//i.e. Hydrogen
public readonly string name;
//atmoic number, i.e. 1
public readonly int number;
//mass number i.e. 1.00784
public readonly double mass;
/// <param name="symbol"> symbol of the element </param>
/// <param name="name"> name of the element </param>
/// <param name="number"> atomic number </param>
/// <param name="mass"> atomic mass </param>
/// <example> Usage: <c> new Element("H", "Hydrogen", 1, 1.00) </c> </example>
public Element(string symbol, string name, int number, double mass) {
this.symbol = symbol;
this.name = name;
this.number = number;
this.mass = mass;
}
/// <returns> true iff other is an Element and has the same atomic number. </returns>
public override bool Equals(object other) {
if(other is Element) {
return ((Element) other).number == number;
}
return false;
}
/// <returns> Unique integer representation of this element. </returns>
public override int GetHashCode() {
return number;
}
/// <returns> string in format "symbol,name,number,mass" </returns>
public override string ToString() {
return new StringBuilder(symbol)
.Append(',').Append(name)
.Append(',').Append(number)
.Append(',').Append(mass).ToString();
}
}
}