| Lab | Assigned | Design Due (Mondays 2 PM) |
Lab Due (Fridays 2 PM) |
|||
|---|---|---|---|---|---|---|
| 22 | Jan | 25 | Jan | 29 | Jan | |
A sample working version of this lab has been implemented by the instructor . You can run this to get an idea of how the project should work. If you are unsure about how something should work, please get help .
Lab2.java
Startup, either as an Applet or as a
standalone application. It may seem mysterious, but the invocation of
Startup.start() causes Startup's run
method to execute. For now, trust
me--- CS 102 covers
threads.
You should not modify this file.
Startup.java
void run()
run method is where things really
get started for this lab. The method invokes three test methods
that should exercise the CS101Canvas, the MousePad,
and the SegmentDisplay. The method then constructs
a MousePad and SegmentDisplay for the
Craf-ta-Graf.
Some code follows that "doodles" on the display. Thereafter, a loop
repeatedly gets a gesture from the MousePad and passes it
on to the SegmentDisplay.
You need not modify this method.
void testCanvas()
click() and
Line, as you will find these useful for the MousePad
and SegmentDisplay.
testDirectionVector
DirectionVector class and its methods. Your
grade will be partly based on how thoroughly you test your work.
void testMousePad()
MousePad and reads
three gestures from it, reporting the results using
Terminal.println(String).
You need not modify this method, but it won't report anything useful until
your MousePad is functional.
void testSegmentDisplay()
SegmentDisplay.
Nothing nice will appear until your SegmentDisplay is
functional.
DirectionVector.java
DirectionVector.java.
Notice that the
class name exactly matches the file name, including capitalization. Java
expects this, so when you define classes from scratch, be sure to follow
this convention.Remember: when the name of a parameter of a method matches the name of an instance variable in the same class, it "masks" the instance variable. However, you can still refer to the instance variable by preceding it with "this." For example, this.x = x will assign the value of the parameter x to the instance variable named x. Within a method, this always refers to the object on which the method has been invoked (i.e., "this" object).
(new DirectionVector(4,3)).toString()could have the string value "(4,3)" as its return value. As a rule, you should provide a toString method for every class you write, since Java uses that method when it concatenates the value of a variable to a string. For example, the existence of the toString method allows us to do the following:
DirectionVector v = new DirectionVector(5,2);
Terminal.println("Created the vector " + v + ".");
with the resulting output:
Created the vector (5,2).
Startup.java as described above.
MousePad.java
DirectionVector getGesture()
DirectionVector. Process a gesture as follows:
DirectionVector that captures the
vector from the first to the second click.
String toString()
SegmentDisplay.java
void addSeg(DirectionVector)
DirectionVector.
Remember that the new segment must start from the end of the
previous segment. You will probably have to add some instance variables
to SegmentDisplay, along with code to maintain them, so that
you can "remember" where you left off.
A segment can be drawn
by the
appropriate call to Line from
CS101Canvas.
Note that the segments you draw should never stray outside the display. Like its toy analog (Etch-a-Sketch), attempts to go outside the display are stopped at the edges.
DirectionVector minCorner() and DirectionVector maxCorner()
utilization
To the greatest extent possible, do not duplicate code in your class. Instead, make use of the methods you have defined.
String toString()
The following items should be stapled together (in order) and turned into the correct CS101 bin (by your section letter) by 2 P.M. on the due date. (Beginning with Lab 2, all work you turn in should be prepared according to the CS101 Style Guide.) Double check that you have completed all header information.
Startup.java
(contains your test code for DirectionVector)
DirectionVector.java
MousePad.java
SegmentDisplay.java
Important note about testing: Think carefully about your test cases, to be sure they cover the various possible cases. Your test procedures should print out enough information for someone to understand what is being tested. For example, be sure to print the method name, parameters and return values in the test program as you call each method of your objects. Your output must be clear and well organized to receive full credit on this lab. Remember to turn in your transcript!
Important note about demos: You will have to demonstrate your lab (i.e., let a TA execute your program) in your next lab section immediately following the due date. If you are not in your lab section to give a demonstration, we will assume that your program doesn't work.