A mutator that preserves a clock invariant

A Java class TimeOfDay stores the time as a private count of minutes since midnight and promises the invariant 0 <= minutes && minutes < 1440. Its method addMinutes(int n) must move the time forward for positive n and backward for negative n, wrapping around midnight. Assume the size of n is under one million, so no overflow occurs. Which body for addMinutes keeps the invariant and produces the correct time for every such n?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Encapsulation and Information Hiding Questions: