CS351 - Design of Large Programs - Professor Ackley

Tuesday and Thursday: 11:00am - 12:15pm (Centennial B146) Labs: Monday (001) 1:00pm - 1:50pm and Thursday (005) 12:30pm - 1:20pm (Centennial B146)

Lab #5: Debugger

Learn how to visually debug using the debugger within the Eclipse IDE.

Goals

  • Go over debugging mode
  • Breakpoints
  • Step Over, Step Into, Step Return, Continue, Stop
  • Variables Window and Hover
  • Turn in a hard copy of answered debugging questions by the end of the lab

Needs


Background

"Best way to cut down debugging time? Don't write bugs." - Professor Ackley

Debugging at some point in your life will be inevitable. Until we can accomplish what Professor Ackley suggests (Hint: this will be never), we need to take as much help as we can get when it comes to cutting down the time it takes to debug our code. Far too many hours have been spent using "poor man" debugging tools (i.e. inline print statements, visual inspection, etc.) when you have a fully graphical debugger at your fingertips.

Break.
Review frozen state.
Step through.
Kill your bug.


//TODO

You are given a .jar file which contains an interface (Bugger) and an implementation of that interface, BuggerImpl. The point of the BuggerImpl object is as follows:
Based on the words provided in the constructor of a BuggerImpl, the program stores the words and their lengths. Then, the caller can ask the BuggerImpl to calculate the average length of the stored words. A double is returned.

It turns out that the implementation has a few errors. Your job is to find these errors by using the built in Eclipse Debugger.

Add the provided Bugger.jar file TO YOUR BUILD PATH. Do not import the code. I attached the .java source code to this .jar so you will be able to add breakpoints and step through the code used in the BuggerImpl.java.

Download the BuggerDriver.java file and import this. We will be running this file's main method to start our program.

There are 3 parts to this assignment. Each part contains a different set of input values that we will give to the constructor of a BuggerImpl through the String[] args in the main method of BuggerDriver.java.

  1. Input: "Welcome student!"
    Expected output: 14/2 = 7.0 is the average length per word.
  2. Input: "Let's play baseball!!!!"
    Expected output: 16/3 = 5.33 is the average length per word.
  3. Input: "Yay! Wow! What a cool laboratory!"
    Expected output: 25/6 = 4.166667 is the average length per word.

The inputs do not contain the quotes. The arguments in the run configuration should be everything inbetween the quotes.


Your job is to answer the 2 questions marked by the non-javadoc comments /**QUESTION #1: **/ and /**QUESTION #2:**/. The second question must be run on the 2nd input. These questions must be answered by setting breakpoints throughout the code and navigating to a point where you can view state that will answer the question appropriately.
In addition to this, the 2nd input calculates the average length per word incorrectly. Why is this? Use breakpoints and the debugger to find the error and how you would fix it.
Finally, the 3rd input causes an IndexOutOfBoundsException. Why is this? How would you fix it?

NOTE: You don't actually have to rewrite the code correctly. All I need from you is a sheet of paper that tells me where the error is and how you would fix it.

Turn in a sheet of paper answering questions #1 and #2 and describing the cause of the incorrect calculation in the 2nd input and why the 3rd input throws an exception. Make sure to include your solutions on how you would go about fixing this bug. Turn this into me before you leave lab.