A StepTracker object is created with a parameter that defines the minimum number of steps that must be taken for a day to be considered active. The StepTracker class provides a constructor and the following methods.
- addDailySteps, which accumulates information about steps, in readings taken once per day
- activeDays, which returns the number of active days
- averageSteps, which returns the average number of steps per day, calculated by dividing the
total number of steps taken by the number of days tracked. Write the complete StepTracker class, including the constructor and any required instance variables and
methods. Your implementation must meet all specifications and conform to the example.
public class StepTracker
{
// instance variable declarations here
// constructor with a parameter here
// accessor method activeDays() here.
// Write the mutator method addDailySteps here.
// @param number of steps taken that day
public static void main(String[] args)
{
StepTracker tr = new StepTracker(10000);
// returns 0. No data has been recorded yet.
System.out.println(tr.activeDays());
// returns 0.0. When no step data have been recorded,
// the averageSteps method returns 0.0
System.out.println(tr.averageSteps());
// This is too few steps for the day to be considered active.
tr.addDailySteps(9000);
// This is too few steps for the day to be considered active.
tr.addDailySteps(5000);
// returns 0. No day had at least 10,000 steps.
System.out.println(tr.activeDays());
// returns 7000.0 The average number of steps per day is (14000/2).
System.out.println(tr.averageSteps());
// This represents an active day.
tr.addDailySteps(13000);
// returns 1. Of the three days for which step data were entered,
// one day had at least 10,000 steps.
System.out.println(tr.activeDays());
// returns 9000.0. The average number of steps per day is (27000/3).
System.out.println(tr.averageSteps());
tr.addDailySteps(23000); // This represents an active day.
tr.addDailySteps(1111); // This is too few steps for the day to be active.
// returns 2. Of the five days for which step data were entered,
// two days had at least 10,000 steps.
System.out.println(tr.activeDays());
// returns 10222.2. The average number of steps per day is (51111/5).
System.out.println(tr.averageSteps());
}
}