CS 2 (Winter 2021)Lab 02: Text Adventure

This lab focuses on debugging a text adventure we have written. The complexity of the code is closer to a proper CS 2 project than you’ve seen yet, but, of course, you won’t be writing it today; instead, you’ll be debugging it!

Setup

Register for the lab using grinch: https://grinch.caltech.edu/register and clone the repository as explained in the setup instructions.

Install the IntelliJ Visualizer

See the instructions here.

Goals and Outcomes

In this lab, you will enhance your code debugging abilities by debugging a text adventure we have written. We’ll guide you through this process, but the intention is to make this a realistic debugging experience.

By the end of this lab, you will…

• be able to read stack traces
• be better able to approach debugging code
• get experience with more of the kinds of errors you’ll run into during this course

Part 0: Run the (broken) Game and the (failing) Tests

The very first thing you should do is use the dropdown in the top right to first run through the game. This will give you a sense of what the program you are debugging is actually supposed to do. Then, after you’ve run the game, run the tests; they should fail on BirdCountingStage which will lead you into debugging the first error below.

Part 1: Debug BirdCountingStage

When a runtime error occurs in Java, a stack trace is printed to the console to provide information on where the error occurred and what steps the program took to get there. When running the tests for the first time, your stack trace will look like this:

The first thing to note is what kind of error occurred; this is shown at the first line of the stack trace. In this case, our code threw a NullPointerException.

The lines beneath it represent the sequence of methods the program took to arrive at the error: the first line in the list is where the error occurred, and the line beneath it represents the line of code that called the method which threw the error, and so on.

It turns out that this isn’t the only error in this class!

Getting Checked Off

At the end of every lab, you will need to call over a member of course staff to review your work. Sometimes, we will ask you to think about questions that you’ll review with the person who checks you off. For this lab, please answer the following questions: