Lab 4: Concept Review and Project 0

Please report any errors directly to us: cs61b@eecs.berkeley.edu

A. Before You Start

B. Some Review

We'll start with some review exercises on the subjects of pointers and OOP:

C. Project 0

Take a look at the Project 0 specification. Set up your working directory with its files in the usual way (see the instructions in the specification if you're not sure how. Take particular care about the git push -u origin ... step, so that you don't end up trying to push to our repository instead of yours.

Compile the code in the canfield and in gui (the command make will do this), and play around a bit with the text interface to the Canfield game (after first looking at the rules in the spec, if you need them):

java -ea canfield.Main --text

(-ea means "enable assertion statments", generally a good idea when developing code).

The command help will print out a list of commands you can use. Play with it enough to understand what the program does from the user's perspective. Run the (broken) GUI version, too:

java -ea canfield.Main 

Now try running the sample GUI code:

java gui.Main

Clicking on an empty area creates a new point. Clicking on an existing point and then moving the mouse to another point and clicking it will create a line segment (an edge) between the points. Dragging a point will move it and any attached edges.
Now go into the files gui/SampleData.java and gui/SampleGUI.java and see if you can figure out how to add a new menu button that clears just the edges between points, not the points themselves.
You might find the documentation of the ucb.gui package, especially the TopLevel class, to be helpful.

Go into the file gui/DataSisplay.java and see if you can figure out how to draw the points as filled red circles instead of images of bears. You will probably find the documentation of java.awt.Graphics and its subtype java.awt.Graphics2D to be helpful.

There is nothing to submit for this lab.