@Test void testEmpty() { Calculator calculator = new Calculator(); try { calculator.average(); fail("Should have had an exception"); } catch(NoElementsException e) { } }
public Double average() throws NoElementsException { Double total = 0.0; if(values.isEmpty()) { throw new NoElementsException(); } for (Double value : values) { total += value; } return total/(double)values.size(); }
Calculator { public Double average() throws NoElementsException { Double total = 0.0; if(values.isEmpty()) { throw new NoElementsException(); } for (Double value : values) { total += value; } return total/(double)values.size(); } }
Calculator { public Double average() throws NoElementsException { Double total = 0.0; if(values.isEmpty()) { throw new NoElementsException(); } for (Double value : values) { total += value; } return total/(double)values.size(); } Calculator(); }
Calculator { public Double average() throws NoElementsException { Double total = 0.0; if(values.isEmpty()) { throw new NoElementsException(); } for (Double value : values) { total += value; } return total/(double)values.size(); } Calculator(); void add(Double value); Double average(); Double median(); }
Calculator { public Double average() throws NoElementsException { Double total = 0.0; if(values.isEmpty()) { throw new NoElementsException(); } for (Double value : values) { total += value; } return total/(double)values.size(); } Calculator(); void add(Double value); Double average(); Double median();  }