Problem Statement
Suppose it is 4:30. The hour hand of a clock would be halfway between 4 and 5.
The image of the clock in a mirror would cause the hour hand to reside in the
region between 7 and 8 (by perception only, if you couldn't see the numbers).
The minute hand is pointed directly down, so its image in the mirror is in the
same place as it is not in the mirror. Therefore, in a mirror, the time would
appear to be 7:30.
Write a class Mirror that contains a method mirror, which takes as argument a String representation of a clock and returns the observed time if the clock were seen in a mirror.
Assume that it is a 12 hour clock and that it has an hour hand and a minute hand that move continuously at their respective speeds. Thus, when it is 12:00, both hands point straight up.
Write a class Mirror that contains a method mirror, which takes as argument a String representation of a clock and returns the observed time if the clock were seen in a mirror.
Assume that it is a 12 hour clock and that it has an hour hand and a minute hand that move continuously at their respective speeds. Thus, when it is 12:00, both hands point straight up.
Definition
- Class:
- Mirror
- Method:
- mirror
- Parameters:
- String
- Returns:
- String
- Method signature:
- String mirror(String time)
- (be sure your method is public)
Notes
- The return format is expected to be the same as the input, so that mirror is its own inverse. That is, given a valid input s, then mirror (mirror (s)) is the same as s.
Constraints
- time will be of the form "x:y" where x is an integer between 1 and 12, inclusive, and y is an integer between 00 and 59, inclusive.
- There are no leading zeros on the hours portion of the time.
- There is exactly one leading zero if the minutes is between 0 and 9, otherwise no leading zeros (for example, 12:00, 12:01, 12:09, etc).
Examples
"12:00"
Returns: "12:00"
"10:45"
Returns: "1:15"
"3:07"
Returns: "8:53"
"2:00"
Returns: "10:00"
"11:59"
Returns: "12:01"
"6:40"
Returns: "5:20"
"6:00"
Returns: "6:00"
"7:01"
Returns: "4:59"
"7:59"
Returns: "4:01"
"10:51"
Returns: "1:09"
"12:59"
Returns: "11:01"
"10:00"
Returns: "2:00"
"7:47"
Returns: "4:13"
"6:58"
Returns: "5:02"
"12:30"
Returns: "11:30"
"11:58"
Returns: "12:02"
"2:53"
Returns: "9:07"
"12:01"
Returns: "11:59"
"3:07"
Returns: "8:53"
"11:51"
Returns: "12:09"
"11:15"
Returns: "12:45"
"11:55"
Returns: "12:05"
"1:00"
Returns: "11:00"
"6:30"
Returns: "5:30"
"3:42"
Returns: "8:18"
"11:59"
Returns: "12:01"
"2:30"
Returns: "9:30"
"11:30"
Returns: "12:30"
"11:00"
Returns: "1:00"
"11:57"
Returns: "12:03"
"12:13"
Returns: "11:47"
"8:57"
Returns: "3:03"