-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElement.java
More file actions
50 lines (46 loc) · 1.36 KB
/
Element.java
File metadata and controls
50 lines (46 loc) · 1.36 KB
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
/**
* This class represents an element.
*/
public enum Element
{
CARBON ("C"),
HYDROGEN("H"),
NITROGEN("N"),
OXYGEN ("O"),
SULFUR ("S");
/** the atomic symbol for this element */
public String symbol;
/** Constructor. */
Element(String symbol)
{
this.symbol = symbol;
}
/**
* Returns the Element corresponding to the inputted String.
* @param symbol the symbol for the requested element
* @return the corresponding Element enum element
*/
public static Element getElement(String symbol)
{
if ( symbol.equals("C") || symbol.equals("CA") )
return CARBON;
else if ( symbol.equals("H") || symbol.equals("HN") || symbol.equals("HS") || symbol.equals("HO") )
return HYDROGEN;
else if ( symbol.equals("N") )
return NITROGEN;
else if ( symbol.equals("O") || symbol.equals("O-") || symbol.equals("OH") )
return OXYGEN;
else if ( symbol.equals("S") || symbol.equals("SH") || symbol.equals("SS") )
return SULFUR;
else
throw new IllegalArgumentException("Unrecognized atom symbol (" + symbol + ")!");
}
/**
* Returns a string representation of this Element.
* @return the String
*/
public String toString()
{
return String.format("%s", symbol);
}
}