Enumerated types in Java are quite powerful, in that they can contain methods and instance variables. An enum type class automatically has a static values method added by the compiler that returns an array containing all of the values of the enum in the order in which they were declared.

You will complete the Elements enumeration which declares elements with their symbols and melting points. Your tasks are as follows:

Table of melting points:

Element Symbol Melting Point
Hydrogen H -258.975
Oxygen O -222.65
Nitrogen N -209.86
Chlorine Cl -100.84
Mercury Hg -38.72
Potassium K 63.35
Sodium Na 98.0

Complete the following file:


import java.util.ArrayList; /** Element enumeration defines elements, their symbols, and their melting points. */ public enum Element { // TODO: Define enumerated values for each entry in the table private String symbol; private double meltingPoint; // TODO: Complete the constructor Element (String aSymbol, double aMeltingPoint) { } public double getMeltingPoint() { return meltingPoint; } public String toString() { return symbol; } //TODO: complete the getMeltedElements method. /** Returns a list of elements whose melting points are less than or equal to a given temperature. @param boundaryTemp the cutoff temperature value @return a list of elements that will melt at the boundary temperature */ public static ArrayList<Element> getMeltedElements(double boundaryTemp) { } }

Use the following file:


public class ElementTester
   public static void main(String[] args)
      System.out.println("Expected: [H, O, N, Cl, Hg]");
      System.out.println("Expected: []");
      System.out.println("Expected: [H, O, N, Cl]");
      System.out.println("Expected: [H, O, N, Cl, Hg, K, Na]");