1. |
Answer: |

2. |
It is tedious to type in lots of test data every time you find a bug in your code. How can you reduce your workload? Answer: |

3. |
Provide a test harness for randomly generated test cases. Answer: |

4. |
Did you think of boundary cases? What are the boundary cases in this example? Answer: |

5. |
Answer: |

6. |
Did one of your test cases catch it? If yes, which one? Answer: |

7. |
Answer: |

8. |
Compile and run the class. Either use BlueJ or supply a test harness. Then enter the test cases that you supplied. Does each branch work as expected? Answer: |

9. |
Answer: |

10. |
If the test succeeds, how much confidence do you have that power is correct? Answer: |

11. |
Use the fact that x Answer: |

12. |
(Extra credit) Which way is actually faster, power(double a, int n) or x Answer: |

13. |
Answer: |

14. |
Show the resulting trace when power is called with a = 3 and n = 11. Answer: |

15. |
The disadvantage of print statements is that you need to remove them when your code is debugged. Therefore, it is better to use the logging facility. Replace the print statements with logging calls in the Numeric.power method. Answer: |

16. |
Run your modified method with a = 2 and n = 12. Exactly what logging output do you get? Answer: |

17. |
The following portion of the lab is designed to have you practice some of the basics of debugging. We will analyze a program that displays Pascal's triangle. This triangle is a sequence of integers that arises in numerous areas of math and computer science, especially combinatorics and probability. For example, the Pascal triangle of height 4 is: Answer: |

18. |
Here is a class that makes a Pascal triangle of a given height. It also makes a test harness. Answer: |

19. |
When the height is 5, we expect six rows. There aren't enough rows. To find out why, set a breakpoint at the line Answer: |

20. |
Now run the program until it reaches the breakpoint again. What value do you expect n to have, and what value do you actually observe? Answer: |

21. |
The variable n is supposed to take the values 0, 1, 2, 3, 4, 5, but it actually jumped from 0 to 2. Answer: |

22. |
Run your corrected version again with a height of 5. You should now have six rows of output, but the values are still wrong. What values do you get? How do you know they are wrong? Answer: |

23. |
To dtermine why the values are still wrong, set a breakpoint at the line Answer: |

24. |
C(3, 1) is 3! / (1! * 2!) = 6 / (1 * 2) = 3. Check why the value is computed incorrectly, and fix the computation. What fix did you apply? Answer: |

25. |
After fixing the error, run the test again. What values do you get? Answer: |

26. |
Is the program correct now? Answer: |