Using DrJava for the "GridWorld" Case Study

( last modified Monday, 29-Nov-2010 00:54:33 UTC )


Introduction

The "GridWorld" Case Study

The "GridWorld" Case Study is part of the Advanced Placement (AP®) Computer Science curriculum. It is required in both the A and AB course syllabi. The case study is an interactive, graphical program that simulates the behavior of different objects.

DrJava is a light-weight development environment that is well suited for student projects involving the case study. This page provides some instructions on how to use DrJava for the "GridWorld" Case Study.

Download from the AP Website

You can find all of the "GridWorld" Case Study materials at the AP® Computer Science website.

The source code for the case study is available in a ZIP file on that website. You may need a program to extract the ZIP file, e.g. WinZip.

Downloading and Installing DrJava

DrJava is a pure Java application that is distributed in three different forms: as a Java jar file, as a Windows .exe file, and as a Mac OS X application. The jar distribution will run on all platforms that support Java. On Windows, the Windows .exe file is usually more convenient because the it wraps the jar file inside a a script that finds the Java compiler (which can be in a variety of locations on Windows) before it starts DrJava, freeing the user from manually entering its location the first time DrJava is executed. On Mac OS X, the DrJava Mac application is a better choice than the jar file because it wraps the jar file in a "Mac app" that conforms to the user-interface conventions of the Mac platform. To install DrJava:

  1. If you have not already installed a Java SE Development Kit (JDK), version 5 or 6, download and install one from the Sun Microsystems website. DrJava requires a Java Development Kit (JDK), rather just a Java JRE (virtual machine), because the JDK includes the javac compiler.
  2. Download DrJava from our website. No "install" step is necessary; to run DrJava simply click on the icon for the file that you downloaded. If clicking on the jar file icon fails for some reason, see our instructions on how to run the DrJava jar file from the command line.

If you need help with any of these steps, please watch our video tutorials or contact us.


Using DrJava for the Case Study

Description of the Different Download Options

For your convenience, we provide two versions of the "GridWorld" source code for use with DrJava. The first version contains individual projects corresponding to the separate chapters of the case study. We recommend using this option, since students only have to work with the files necessary for the respective chapters. The projects are completely configured and ready to use with DrJava.

The second version contains the entire source code for all chapters configured as a single DrJava project.

Another option is to download the source code from the AP® website and create the DrJava project yourself. We provide descriptions on how to do that.


Download Option 1: Source Split Into Individual Chapters

For your convenience, we have created several different project files that correspond to the programs studied in the individual chapters of the case study. To use the project files, please follow these instructions:

  1. Download the case study materials with DrJava separate project files from our website. You do not need material from the the AP® Computer Science website.
  2. Unpack the archive into a directory of your choice. You may have to use a separate program like WinZip to extract the ZIP file.
  3. The directory where you unpacked the archive now contains four DrJava project files:
    • firstProject.xml is the project for part 1.
    • boxBug.xml is the project for part 2.
    • critters.xml is the project for part 4.
    • framework.xml is the project for parts 3 and 5.
  4. To open a project file,
    1. Run DrJava.
    2. Use the Open command in the Project menu (or press Ctrl+I).
    3. Find the project file you want to open and press the Open button.
    You are now ready to edit, run, and compile the project with DrJava. For more information about how to do that, please take a look at our Documentation and QuickStart Guide.

Note: Parts 3 and 5 do not specify which classes should be run; these parts ask you to study the source code. If you press the Run button in DrJava, you will get an error Static Error: This class does not have a static void main method accepting String[].
To run programs, please open the project files for parts 1, 2 or 4.


Download Option 2: Source as a Single Project

If you prefer the source code not to be split up by chapters, here are instructions on how to use our pre-made project file that contains all the source code of the case study:

  1. Download the case study materials with a single DrJava project file from our website. You do not need material from the the AP® Computer Science website.
  2. Unpack them into a directory of your choice. You may have to use a separate program like WinZip to extract the ZIP file.
  3. The project and framework directories have been merged into a single source directory.
  4. There is a single DrJava project file called gridWorldAll.xml. It contains the source code for all five parts of the case study.
  5. To open a project file,
    1. Run DrJava.
    2. Use the Open command in the Project menu (or press Ctrl+I).
    3. Find the project file you want to open and press the Open button.
    You are now ready to edit, run, and compile the project with DrJava. For more information about how to do that, please take a look at our Documentation and QuickStart Guide.
Note: The project file is set up to run the BugRunner class for part 1. To run the BoxRunner class for part 2 or the CritterRunner class for part 4, please change the Main Class in the Project Properties (see documentation), or type one of the following in the Interactions Pane:
run BoxRunner
or
run CritterRunner


Download Option 3: Do-It-Yourself

If you like, you can also create the project for DrJava yourself as follows:

  1. Download the case study materials from the AP® Computer Science website.
  2. Unpack them into a directory of your choice. You may have to use a separate program like WinZip to extract the ZIP file.
  3. To create a project file,
    1. Run DrJava.
    2. Use the New command in the Project menu.
    3. Pick a name for the new project file, select a place to save it, and press the Save button. We suggest you save it in the case study directory.
    4. In the Project Properties dialog, edit the project settings as described below.
    5. Set the Project Root to the directory that corresponds to the default package:
      • Part 1: projects/firstProject
      • Part 2: projects/boxBug
      • Part 4: projects/critters
      • Parts 3 and 5: framework
    6. Click on the Add button in the Extra Classpath section, find the gridworld.jar file in the case study directory, and press the Select button to add the gridworld.jar file to the "Extra Classpath".
    7. Optional: If you want the class files to be saved in a directory separate from the Java source files, press the top ... button in the "Build Directory" row and navigate to the case study directory. Now press the Make New Folder button and enter a name for the directory, e.g. classes. Select the new directory and press the Select button.
    8. Optional: If you want to use the "Run Project" button of DrJava to run the project, enter the main class name in the Main Class field. Depending on the case study part, enter:
      • Part 1: BugRunner
      • Part 2: BoxBugRunner
      • Part 4: CritterRunner or CrabRunner or ChameleonRunner
      • Parts 3 and 5 cannot be run.
    9. Press the OK button to close the Project Properties dialog.
    10. Use the Open Folder... command in the File menu and select the directory you selected as project root in step 3.e., then press the Select button.
    11. The source files are now displayed on the left side of the editor.
    You are now ready to edit, run, and compile the project with DrJava. For more information about how to do that, please take a look at our Documentation and QuickStart Guide.


Notes

DrJava Compiler Warnings when Compiling Case Study

When you are using DrJava to compile the case study source code, you may see one or both of the following compiler warning:

File: /Users/mgricken/Desktop/GridWorldCode_DrJava_AllTogether/source/info/gridworld/grid/BoundedGrid.java  [line: 90]
Warning: [unchecked] unchecked cast
found   : java.lang.Object
required: E

This warning is generated because the case study contains a generic BoundedGrid class that uses a plain Object array to store elements of type E. The warning is unavoidable in generic Java. Other development environments often ignore these warnings by default; however, we chose to display these warnings to enable students to write code that is as timely and correct as possible.

You may either disable the warnings in DrJava or change the source code, as described below:

  • Disabling the Warnings in DrJava
    1. Use the Preferences... command in the Edit menu.
    2. In the Preferences dialog, switch to the Compiler Options category.
    3. Disable the Show Unchecked Warnings option.
    4. Press the OK button.
  • Changing the Source Code
    1. In the BoundedGrid.java file, find the get method.
    2. Change the line
      public E get(Location loc)
      to
      @SuppressWarnings("unchecked") public E get(Location loc)

Old "Marine Biology Simulation" Case Study

We also have instructions available for the previous case study, the "Marine Biology Simulation".

Hosted by SourceForge.net DrJava has been partially funded by the National Science Foundation, the Texas Advanced Technology Program, and Sun Microsystems, Inc.