Followers 0

## 2 posts in this topic

Does anyone know if there are any answers floating around to the exercises in Think Java: Think like a computer scientist by Allen Downey?

I'm stuck on exercise 2.11 - the 24 hour clock.

Thanks for any replies
-1

##### Share on other sites
Any one care to help me understanding this?
I found what is supposed to be the answer but I can't wrap my head around it. Like where did the 3600 come from on this line
seconds_since_midnight = hour * 3600 + minute * 60 + second;

Thanks for any help
[source lang="java"]public class time { public static void main(String[] args) {
int hour, minute, second, seconds_since_midnight, seconds_remaining, percentage_passed;
hour = 20;
minute = 14;
second = 29;
seconds_since_midnight = hour * 3600 + minute * 60 + second;
System.out.print("Seconds since midnight: ");
System.out.println(seconds_since_midnight);
seconds_remaining = (24 - hour) * 3600 + (60 - minute) * 60 + (60 - second);
System.out.print("Seconds remaining in the day: ");
System.out.println(seconds_remaining);
percentage_passed = seconds_since_midnight * 100 / (3600 * 24);
System.out.print("Percentage of the day that has passed: ");
System.out.println(percentage_passed);

}

}[/source] Edited by Jeffige
0

##### Share on other sites
An hour is 60 minutes, and a minute is 60 seconds. You get the 3600 seconds to an hour by simple multiplication.
2

## Create an account

Register a new account