Class RunningAverage

  • All Implemented Interfaces:
    Average

    public class RunningAverage
    extends java.lang.Object
    implements Average
    Implements a simple running average.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private long count  
      private double sum  
    • Constructor Summary

      Constructors 
      Constructor Description
      RunningAverage()
      Create a new running average.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      double getAverage()
      Return average-so-far.
      void reset()
      sets back to start-of-day
      double update​(double newValue)
      Update average and return average-so-far.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • count

        private long count
      • sum

        private double sum
    • Constructor Detail

      • RunningAverage

        public RunningAverage()
        Create a new running average.
    • Method Detail

      • reset

        public void reset()
        Description copied from interface: Average
        sets back to start-of-day
        Specified by:
        reset in interface Average
      • update

        public double update​(double newValue)
        Update average and return average-so-far.
        Specified by:
        update in interface Average
      • getAverage

        public double getAverage()
        Return average-so-far.
        Specified by:
        getAverage in interface Average