Java

OOP GUIDE / WORK

 

STEPTRACKER CLASS

 

Topics

  • Advanced class design

 

Source

  • This question was part of the 2019 AP exam free response questions.  You can find all four of the original questions here on the AP site.

 

 

TASK – PART 1 – STEPTRACKER CLASS

 

Click here for a PDF containing the specification of the StepTracker class that you must implement.

 

 

TASK – PART 2 – TESTING THE STEPTRACKER CLASS

 

Copy and paste the following code that will test your StepTracker class.  Note that the program below matches the example method calls in the PDF document.  You should compare your output to the output in the PDF document to see if they match.

 

 

public class StepTrackerTester

{

     public static void main(String[] args)

     {

           StepTracker tr = new StepTracker(10000);

           System.out.println(tr.activeDays());

           System.out.println(tr.averageSteps());

           tr.addDailySteps(9000);

           tr.addDailySteps(5000);

           System.out.println(tr.activeDays());

           System.out.println(tr.averageSteps());

           tr.addDailySteps(13000);

           System.out.println(tr.activeDays());

           System.out.println(tr.averageSteps());

           tr.addDailySteps(23000);

           tr.addDailySteps(1111);

           System.out.println(tr.activeDays());

           System.out.println(tr.averageSteps());

     }

}