 The purpose of this program is to take two time intervals, for example, from 5.10 in the morning until 7.45, where the times are expressed in military time notation, and our second interval is from 8.20 until 10.15 in the morning. We want to find out how long it gave restart. The purpose of this program is to take two time intervals expressed in military time, for example, from 5.10 in the morning until 7.45, and from 8.20 until 10.15. Find out how long each interval is, and compare them to see which one is longer. Our first step is going to be to split the numbers into hours and minutes. Let's take the number 510. If we divide it by 100, we get a quotient of 5 and a remainder of 10. There's our hours and there's our minutes. That seems to work with all of the numbers. Let's take 10.15 in the morning, which we read in as the integer 10.15, divide by 100, and we get 10 hours and 15 minutes. So we can add this to our list of things to do. Divide and remainder by 100. The next step is going to be figure out the interval length. The question is how do we do that by hand? Well, let's take our hours and minutes, and our first interval began at 5.10 in the morning and ended at 7.45. Subtract them, and that's 2 hours and 35 minutes. At 60 minutes per hour, that's 120 plus 35. Our first interval is 155 minutes long. For the second interval that began at 8.20 and ended at 10.15, we have a problem. Because the way we did this in school, we were taught we can't take 20 from 15, so we have to borrow an hour and add the 60 minutes here, and now we can subtract and get 1 hour and 55 minutes. That's 60 plus 55 or 115 minutes. The problem with doing this borrowing is that that could be pretty tough to say in Java. Let's look for a different way to figure out the interval. Here's the trick. We're going to take each of the times and convert it into a number of minutes past midnight. 5.10 in the morning is 5 hours, which is 300 minutes, plus 10, which is 310 minutes past midnight. Our ending time of 7.45 is 7 times 60, which is 4.20 plus 45, which is equal to 465. Subtract those numbers, and there's our 155 minutes. Let's try the same technique on the other time interval. It ends at 10.15 and begins at 8.20. That's 10 times 60 is 600 plus 15, which gives us 615 minutes past midnight. 8.20 is 8 times 60 plus 20, which comes out to 500 minutes past midnight, and that comes out to 115 minutes. That's exactly the same as the numbers we got when we did it the way we would have done it in school, except this time there's no borrowing that has to be done. We'll add to our list of steps, multiply hours times 60, and add minutes, and then subtract start from end. Our third step will be to compare the resulting length, and then we have to find whether they overlap or not. And the way you can tell if they overlap or not is if the start time of the later interval is before the end time of the earlier interval. In our case, the start time of the second interval, 8.20, is well after the end of the first interval, and that means that these intervals don't overlap. There are some important things to notice here. First of all, I haven't been anywhere near a computer while I've been doing this. If I were at the computer, the monitor would be whispering, look at me, and the keyboard would be whispering, type something. By working here at the table with no computer anywhere near me, I can focus on the task and not be distracted by the computer itself. It'll avoid the temptation of jumping in and starting to write code before everything is planned out. The second thing to note is that I took an actual set of intervals and did the math by hand. It's really hard to explain to a computer how to solve a problem if you don't know how you're solving it yourself. Additionally, as I solved the problem, I wrote down what the steps were. I can now use this to refer to when I write the actual Java code. This is the power of planning. Always plan your programs before you start them. Solve the problem by hand. As you're solving it, ask yourself, what steps am I doing? Why am I doing it this way? Is this something that I can translate into Java? Is there a better or easier way to translate it into Java? The minutes that you take planning can save you hours when it comes to writing the program in Java.