public class
StepTracker
{
private int totalSteps;
private int totalDays;
private int activeDays;
private int activeLimit;
public
StepTracker(int activeLimit)
{
this.activeLimit = activeLimit;
totalSteps =
0;
totalDays =
0;
activeDays =
0;
}
public int
activeDays()
{
return activeDays;
}
public double
averageSteps()
{
if (totalDays ==
0) //careful to avoid
divide by 0 issue
return
0;
else //careful
to avoid int division
return (double)totalSteps / totalDays;
}
public void
addDailySteps(int steps)
{
totalSteps += steps;
totalDays++;
if (steps
>= activeLimit)
activeDays++;
}
}
|