Your task is to complete the implementation of a class that analyzes the peaks and valleys in a data set.

A peak is a value that is larger than the values before and after. A valley is a value that is smaller than the values before and after. The first and last values are neither peaks nor valleys. In other words, a peak or valley occurs if the curve changes direction (from up to down or from down to up).

Complete the following file:

DataSet.java

/** This class collects a number of values and counts the peaks and valleys. */ public class DataSet { private double lastValue; private double precedingValue; private int count; public int peaks; public int valleys; /** Constructs a new data set with no data. */ public DataSet() { // your work here } /** Adds a value to this data set. @param valueToAdd the value to add to this data set */ public void add(double valueToAdd) { // your work here } /** Gets the number of peaks in this data set. @return the number of peaks in this data set */ public int getPeakCount() { return peaks; } /** Gets the number of valleys in this data set. @return the number of valleys in this data set */ public int getValleyCount() { return valleys; } }

Use the following file:

DataSetTester.java

public class DataSetTester
{
   public static void main(String[] args)
   {
      DataSet data = new DataSet();
      data.add(10);
      data.add(20);
      data.add(30);
      data.add(10);
      System.out.println(data.getPeakCount());
      System.out.println("Expected: 1");
      System.out.println(data.getValleyCount());
      System.out.println("Expected: 0");
      data.add(20);
      System.out.println(data.getPeakCount());
      System.out.println("Expected: 1");
      System.out.println(data.getValleyCount());
      System.out.println("Expected: 1");
      data.add(40);
      data.add(50);
      data.add(30);
      data.add(10);
      data.add(10);
      System.out.println(data.getPeakCount());
      System.out.println("Expected: 2");
      System.out.println(data.getValleyCount());
      System.out.println("Expected: 1");
   }
}