SHARE
TWEET

Untitled

advictoriam Mar 5th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Solution Checker is Broken
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5.  
  6. /**
  7.    Element enumeration defines elements, their symbols, and their melting points.
  8. */
  9.  
  10. public enum Element
  11. {
  12.    hydrogen("H", -258.975), oxygen("O", -222.65),
  13.       nitrogen("N", -209.86), chlorine("Cl", -100.84),
  14.          mercury("Hg", -38.72), potassium("K", 63.35),
  15.             sodium("Na", 98.0);
  16.  
  17.    private String symbol;
  18.    private double meltingPoint;
  19.  
  20.    Element (String aSymbol, double aMeltingPoint)
  21.    {
  22.       symbol = aSymbol;
  23.       meltingPoint = aMeltingPoint;
  24.    }
  25.  
  26.    public double getMeltingPoint()
  27.    {
  28.       return meltingPoint;
  29.    }
  30.  
  31.    public String toString()
  32.    {
  33.       return symbol;
  34.    }
  35.    
  36.    /**
  37.       Returns a list of elements whose melting points
  38.       are less than or equal to a given temperature.
  39.       @param boundaryTemp the cutoff temperature value
  40.       @return a list of elements that will melt at the boundary temperature
  41.    */
  42.    public static ArrayList<Element> getMeltedElements(double boundaryTemp)
  43.    {
  44.       ArrayList<Element> list = new ArrayList<Element>(Arrays.asList(values()));
  45.       for(int i = 0; i < list.size(); i++)
  46.       {
  47.          if(list.get(i).meltingPoint > boundaryTemp)
  48.          {
  49.             list.remove(i);
  50.             i--;
  51.          }
  52.       }
  53.      
  54.       return list;
  55.    }  
  56. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top