CS 161 Assignment #1

Due Thursday, September 10th by 11:59pm
(Not accepted after September 14th at class time)

Introduction

This first assignment will give you a chance to explore the shape classes in more detail, and gain additional experience with BlueJ. It requires modifying and extending Java source code, but all of the exercises below can be solved by copying and pasting from the original, running code — you don't need to know how to create any new lines of code from scratch yet.

The Assignment

Start by downloading a fresh copy of UPS_Shapes.zip — the same project you worked on in lab. Extract UPS_Shapes from the compressed directory, open the project in BlueJ, and double-click the Circle class to open the source-code editor. (Make sure you use UPS_Shapes instead of the version from the BlueJ site, otherwise the submission process won't work.)
  1. Modify the Java code so that new circles are yellow by default, instead of blue.
  2. Modify the moveUp, moveDown, moveLeft, and moveRight methods so that they each move the circle 30 pixels instead of 20.
  3. Add a new method called moveNorthEast to the Circle class. When invoked, it should move the circle up by 30 pixels and to the right by 30 pixels. Make sure you add a comment to the code, describing your new method.
  4. Add a new method called shuffleHorizontal that takes a single integer as its argument. When invoked, the method causes the circle to do a slow shuffle to the right by the specified number of pixels, then back to the left, leaving the circle exactly where it started. (That's assuming the input is positive — if the input is negative, the circle will shuffle left, then right.) Add a comment describing your new method. Hint: If your solution is more than a few lines long, you've made this more difficult than it needs to be!
  5. Optional: Modify the code so that circles are visible (on the screen) when they're first created. (No extra points for this one, but completing it will produce a profound sense of well being.)

Submitting

Before submitting, make sure your code compiles, and test each of your modified and new methods thoroughly. When you're convinced that they all work, submit the project just like you did in lab. (The lab is still online, and you can refer back to it if necessary.) The submission process should work from on or off campus. You can submit more than once, but only the most recent submission is kept — it overwrites any earlier submissions.


Brad Richards, 2009