GridWorld (2008 AP CS Exam)

FAQ

Question: I get this error message: bad class file: c:\GridWorldCode\gridworld.jar(info/gridworld/actor/ActorWorld.class) class file has wrong version 49.0, should be 48.0

Answer: Install and use Java 5. You get this error when you try compiling a GridWorld program with Java 1.4 or below.

Question: What is the preferred size for icons?

The preferred image size is 48 x 48 pixels. Other image sizes are acceptable, but they may not look as good due to scaling. Images are scaled isotropically (i.e. preserving the width:height ratio) to fit into tiles and menus. Tiles start at 48 x 48 pixels and can be scaled up or down by a factor of 2, either by user action or in the initial display, to make the all tiles fill the window. The minimum tile size (which is the default in an unbounded grid) is 12 x 12 pixels. Menu icons are 16 x 16 pixels.

Question: Why am I getting a MissingResourceException; can't find bundle for base name info.gridworld.gui.WorldFrameResources, locale en_US?

Answer: Make sure you are using the most current version of the JAR file.

Question: I am using the most current version of the JAR file, but the version number in the Help -> About dialog shows an older version.

Answer: Remove any older versions of the JAR file from your jre/lib/ext directory.

Question: When I run the BoxBugRunner, I cannot add a rock to the world.

Answer: A world knows only the actors that have been added, and their superclasses. If you want to allow students to add rocks, either add at least one rock in the main method, or call the addOccupantClass method on the world.

Question: Why does the case study use Math.random and not java.util.Random?

Answer: This tracks a change in the AP CS subset.

Question: Why do some of the case study methods (such as BoxBug.act) not have method comments?

Answer: When overriding a method, Javadoc automatically inherits the method comment from the superclass. We omit comments unless the subclass method can benefit from a specific comment (as, for example, Location.toString).

Question: Why is there a large number (such as 0.91) in the background of the grid?

Answer: This is the version number. It helps identify the version when someone sends a screen shot to show a problem. The version number is not displayed in the final version of the program.

Question: When clicking on an object and selecting putSelfInGrid, I get this error: java.lang.IllegalStateException: This actor is already contained in a grid.

Answer: That's how it should be.

public void putSelfInGrid(Grid<Actor> gr, Location loc)
puts this actor into the location loc of the grid gr. If there is another actor at loc, it is removed.
Precondition: (1) This actor is not contained in a grid (2) loc is valid in gr

Question: When trying to put an actor outside the grid, an IllegalArgument is thrown.

Answer: That's how it should be.

public void putSelfInGrid(Grid<Actor> gr, Location loc)
puts this actor into the location loc of the grid gr. If there is another actor at loc, it is removed.
Precondition: (1) This actor is not contained in a grid (2) loc is valid in gr

Question: When you go to set the bounded environment with both parameters being zero you get an IllegalArgumentException.

Answer: That's how it should be.

    /**
     * Constructs an empty bounded grid with the given dimensions.
     * (Precondition: <code>rows > 0</code> and <code>cols > 0</code>.)
     * @param rows number of rows in BoundedGrid
     * @param cols number of columns in BoundedGrid
     */
    public BoundedGrid(int rows, int cols)
    {
        if (rows <= 0)
            throw new IllegalArgumentException("rows <= 0");
        if (cols <= 0)
            throw new IllegalArgumentException("cols <= 0");
        occupantArray = new Object[rows][cols];
    }

Question: Why do I get a NullPointerException in the middle of some GridWorld code when a method is invoked on the value returned by getGrid?

Answer: You probably added an actor to the world with the Grid.put or World.add method. You should be using the Actor.putSelfInGrid method.

Question: Why does a new BoxBug(3) trace out a box with side length 4?

Answer: The box corners are intended to be the centers of the grid cells. With this interpretation, the side length is correct. (This is the same interpretation that is used by the java.awt.Graphics class; look at the drawRect method.)

???