(Mondays 2 PM)
(Fridays 2 PM)
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 .
Startup, either as an Applet or as a standalone application. It may seem mysterious, but the invocation of
runmethod to execute. For now, trust me--- CS 102 covers threads. You should not modify this file.
runmethod is where things really get started for this lab. The method invokes three test methods that should exercise the
MousePad, and the
SegmentDisplay. The method then constructs a
SegmentDisplayfor 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
You need not modify this method.
Line, as you will find these useful for the
DirectionVectorclass and its methods. Your grade will be partly based on how thoroughly you test your work.
MousePadand 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
SegmentDisplay. Nothing nice will appear until your
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.javaas described above.
DirectionVector. Process a gesture as follows:
DirectionVectorthat captures the vector from the first to the second click.
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
appropriate call to
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.
To the greatest extent possible, do not duplicate code in your class. Instead, make use of the methods you have defined.
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
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.