This question involves the implementation of a fitness tracking system that is represented by the StepTracker class. 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 will have 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.
The following table contains a sample code execution sequence and the corresponding results.
Statements and Execution
Value Returned Comment (blank if no value) Days with at least 10,000 steps are considered active
StepTracker st = new StepTracker(10000); st.activeDays(); st.averageSteps();
0 0.0
No data have been recorded yet.
When no step data have been recorded, the averageSteps method returns 0.0. This is too few steps for the day to be considered active. This is too few steps for the day to be considered active. No day had at least 10,000 steps. The average number of steps per day is (14000/2). This represents an active day. Of the three days for which step data were entered, one day had at least 10,000 steps. The average number of steps is (27000/3). This represents an active day. This is too few steps to be considered active. Of the five days for which step data were entered, two days had at least 10,000 steps. The average number of steps per day is (51111/5).
st.addDailySteps(9000);
st.addDailySteps(5000);
st.activeDays(); st.averageSteps();
0
7000.0
st.addDailySteps(13000); st.activeDays();
1
st.averageSteps(); st.addDailySteps(23000); st.addDailySteps(1111);
9000.0
st.activeDays();
2
st.averageSteps();
10222.2
To summarize, you will write the complete StepTracker class, which will include: the constructor that takes in the number of steps; the method addDailySteps(int numberOfSteps); the method activeDays(); the method averageSteps().
Your implementation must return correct and acceptable values for the number of steps entered.