AlgoMaster Logo
AlgoMasterDesign Step Trackereasy

Design Step Tracker

easy

Design a StepTracker class that records a person's progress toward a daily walking goal. The tracker keeps a running step total as walks are added and reports that progress in several useful forms.

Implement the StepTracker class:

  • StepTracker(int goal) creates a tracker with the given daily goal and a step total of 0.
  • int addSteps(int count) adds count to the running total and returns the updated total. If count is less than 1, leave the total unchanged and return its current value.
  • int steps() returns the total number of steps recorded so far.
  • int goal() returns the daily goal.
  • int remaining() returns the number of steps still needed. Once the goal is reached or exceeded, return 0 rather than a negative number.
  • boolean goalReached() returns true when the step total is greater than or equal to the goal. Reaching the goal exactly counts as success.
  • int percentComplete() returns progress as a whole-number percentage, rounded down and capped at 100.
  • String summary() returns "<steps> of <goal> steps, goal reached" after reaching the goal. Before then, it returns "<steps> of <goal> steps, <remaining> to go".

Calls accumulate on the same tracker. If two walks add 3000 and 2500 steps, the total becomes 5500. Extra steps are not discarded after the goal is reached: the total may exceed the goal, even though remaining() stays at 0 and percentComplete() stays at 100.

Example 1:

Input:

Output:

Explanation: 4000 steps against a 10000 goal leaves 6000 to walk and puts the tracker at 40 percent, none of which is stored separately.

Example 2:

Input:

Output:

Explanation: Two walks total 5500 against a 5000 goal. The remaining count stops at zero rather than going negative, and the percentage stops at 100.

Constraints

  • 1 <= goal <= 100000
  • -100 <= count <= 50000
  • At most 100 calls in total are made across all methods.

How the design is graded

needs 7/10 to pass
  • Stored versus worked out

    Full marks when only the goal and the running step count are fields, and remaining, percentage and goal status are computed from them when asked. Lose points when any of the three is kept as its own field updated alongside the step count, which is a second copy of the same information.

  • Boundaries

    Full marks when the remaining count stops at zero once the goal is passed, the percentage stops at 100, and hitting the goal exactly counts as reaching it. Lose points heavily when remaining goes negative, or when a strict comparison means an exact hit is not counted.

  • Structure and naming

    Full marks when a count below `1` adds nothing and `summary` uses the same methods the other queries use, so the sentence and the numbers always agree. Lose points when `summary` recalculates them separately or for printing to stdout.

Passing every test is not enough on its own. A submission is accepted only when the design also clears the bar.

Hints

Loading...
CallReturns
new StepTracker(10000)null
addSteps(4000)4000
steps()4000
remaining()6000
percentComplete()40
goalReached()false
summary()"4000 of 10000 steps, 6000 to go"

4000 steps against a 10000 goal leaves 6000 to walk and puts the tracker at 40 percent, none of which is stored separately.

Run checks these cases. Submit also runs a larger hidden set.