The code below is a Java program in applet form for computing the minimum of two integers. You should recognize the minimum subroutine from class. The line numbers are for reference only and do not represent part of the actual code!
Here is what the applet looks like when run from a web page:
The program you will debug in this section is called
AddTimeDebug.java. Debugging this program will be more challenging
than the programs from class. AddTimeDebug.java adds two
time values using only the Java operators mod
(%) and div (/). You should be familiar with
mod and div computations from class.
Here is a quick overview:
| Command | Explanation |
|---|---|
| % | Modulus calculates the remainder when dividing two integers. Example: 190 % 60 = 10 |
| / | In integer division, the remainder is truncated. Example: 190 / 60 = 3 |
The input and output for AddTimeDebug.java are as follows:
Input: Two times specified in minutes and seconds; these are variables of type int which take on values between 0 and 59, inclusive.
Output: The sum of these times, specified in hours, minutes and seconds. Hours is a variable of type int. Can you figure out what the range of possible values is from the input specifications?
For this task, and some future assignments, you will be asked to turn in test data that verifies your program works. To create test data for your program, you should think of all the possible different cases your program may encounter. For this program, you should create a file in your editor called TestAddTime.txt that contains test data for the following cases:
You should make a single line in your file for each test case. Each line should contain four numbers: the first time in minutes and seconds followed by the second time in minutes and seconds. There should be a tab separating the two times on a single line. For example, the first line of your file might look like the following:
0 0 0 0
Once you have thought of values for each test case, save your file TestAddTime.txt. These will be the values with which you test your program. Before continuing, you should try to identify what part of the code corresponds to each test case. You will have to enter the times into your compiled program manually, but this is just to let your grader know what values you had used to make sure your code works.
Now try to compile the code. If it does not compile, check for syntax errors and correct them. Run the code and test for logic errors using your test cases. At this point, you should know which case causes the incorrect output from your program. You should now fix the logic error before continuing. To fix the error, do not rewrite the program, but rather make as few changes as possible to correct the program.