Sign in to follow this  

Think java exercise answers

This topic is 1986 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
Sign in to follow this