Unit 5 Work
Unit 5 CB
public class StepTracker {
private int lowerBound;
private int steps;
private int totalDays;
private int activeDays;
public StepTracker(int minSteps) {
lowerBound = minSteps;
steps = 0;
totalDays = 0;
activeDays = 0;
}
public void addDailySteps(int newSteps) {
steps += newSteps;
totalDays += 1;
if (newSteps >= lowerBound) {
activeDays += 1;
}
}
public int activeDays(){
return activeDays;
}
public double averageSteps() {
if (totalDays == 0) {
return (double) totalDays;
}
else {
return (double) steps / totalDays;
}
}
public static void main(String[] args){
StepTracker tr = new StepTracker(10000);
System.out.println(tr.activeDays());
System.out.println(tr.averageSteps());
tr.addDailySteps(9000);
System.out.println(tr.averageSteps());
tr.addDailySteps(23000);
System.out.println(tr.activeDays());
}
}
StepTracker.main(null);