You're required to follow these naming conventions:
static final ScribbleIfc EMPTY_SCRIBBLEnot
static final ScribbleIfc EmptyScribble
This week, you will be implementing a program we call "Scribbler." You have seen this program in class as a demo, but here's the demo again.
The image above will be a working version of the Scribbler if your web browser supports Java applets. You should experiment with this demonstration version after you finish reading the lab handout to make sure you understand exactly what your program is supposed to do.
Your finished Scribbler program will have three modes: Draw mode, Move mode, and Color mode. The program starts in Draw mode. Draw mode, Move mode, and Color mode are selected by pressing buttons, and the color used by Color mode is selected by choosing a color from a combo box component filled with ColorItem objects. The modes behave as follows:
At any time the user may select a new color, and that color is used for subsequent drawing in Draw mode as well as for changing the color in Color mode.
The program also has an "Erase Last" button that will erase the most recently drawn Scribble. Pressing the button repeatedly will erase Scribbles in the reverse order in which they were drawn. (With what we know so far, there's no easy way to erase an arbitrary scribble that the user points to. You're welcome to implement this if you know how.)
Click this link (while holding the Shift key) to download the Scribble starter script to your home folder.
Now open a terminal window and type
source initScribblerAs a result, there will now be a CS102/lab8 folder containing the following files. (You can also download these files using your browser by clicking on the links below:)
The starter for this lab is a working Scribbler (try it out by compiling everything except the scribble collection classes and interface), but it has only the Draw mode and a simplified Move mode that can move only the most recently drawn Scribble. You will need to add Color mode. More importantly you must implement a recursive data structure that manages a collection of Scribbles, to allow the various modes and the "Erase last" button to work correctly as in the demo.
There are a number of step-by-step approaches you could take to solve this problem, but it is important that you have a plan, and that you add functionality one step at a time. Here is one possible ordering of the tasks. We recommend that you develop and test your program incrementally - make sure you have a working implementation at each step before moving on to the next.
Since your Scribbler class needs to manage a collection of scribbles, which may be empty (an EmptyScribbleCollection) or not (a ScribbleCollection), it needs an instance variable with type ScribbleCollectionIfc. In your begin method, you should initialize it with an object created from EmptyScribbleCollection.
To see how to add a new scribble to the collection, proceed by analogy with the way Scribbler adds a new line to the scribble (see onMouseDrag). Especially notice that there's no way to alter an existing scribble. To "add" a line to the scribble we have, we really create a new scribble, passing it the line and the old scribble.
You will add new Scribbles to your ScribbleCollection in a similar way. Careful though: should you add a new Scribble to the collection in onMouseDrag? Or in onMouseRelease? Or where?
How will the controller class use the constructors and methods defined for scribble collections?
Before turning in your work, be sure to double check both its logical organization and your style of presentation. Make your code as clear as possible and include appropriate comments describing major sections of code and declarations. Remove the comments that no longer make sense because they were provided as guidance for you. Be sure that your code adheres to the naming conventions. Also, don't forget to write your name in all the files you are submitting.
Hand in your program in the usual way: make sure all your java files are in your-home-folder/CS102/lab8. If not, copy them there, and compile and run your program one last time in that folder to make sure that everything works properly.
To submit your files go to moodle in the CS102 course page and the Lab 8 section. There will be separate place to upload for each file. Three questions for you to answer are also provided below, which should be answered in the third activity provided in the moodle under lab 8.
Good luck and have fun!
|Design preparation (3 points total)|
|1.5 points||Simplified color mode|
|1.5 points||Erase mode|
|Style (5 points total)|
|2 points||Descriptive comments|
|1 point||Good names|
|1 point||Good use of constants|
|1 point||Appropriate formatting|
|Design (6 points total)|
|1 point||Good use of boolean expressions, loops, conditionals|
|1 point||Not doing more work than necessary|
|1 point||Use of most appropriate methods|
|1 point||Correct use of ColorItem class|
|2 points||Appropriate recursive structure in ScribbleCollection|
|Correctness (6 points total)|
|1 point||Switching among modes correctly|
|1 point||Draw mode adds correctly to the ScribbleCollection|
|1 point||Move mode works correctly|
|1 point||Color mode works correctly|
|1 point||Erase button works correctly|
|1 point||Color selection works correctly|
|Three feedback questions (4 pts total)|