| Probable Grade | Notes | ||
|---|---|---|---|
| the excellent! | MovingSpecsClient.java | 100% | Adheres to all coding standards AND...
|
| the good | Ch2Client.java | 90 - 95 % | Adheres to all coding standards BUT ... misses the spirit of them. Even class name is not helpful. Probably won't lose all available points but... definitely some. |
| and the ugly | BadClient.java | ??? | (don't miss the TABS) |
Since the most common of these will be the dreaded NullPointerException, it will be especially important to learn what these are about and how to avoid them.
Example,
// Casey Jones
// September 8, 2044
// Homework #1: Problem 5 - p.59 (2.7.4)
// Each mouse press draws a filled 20x20 square.
// Each mouse release leaves a frame of the last square.
| Right |
// construct a square and provide instructions for user
new FramedRect( 200, 200, 50, 50, canvas);
new Text("Clicking makes things happen...", 20, 20, canvas);
|
|---|---|
| Wrong |
// construct a square and provide instructions for user
new FramedRect( 200, 200, 50, 50, canvas);
new Text("Clicking makes things happen...", 20, 20, canvas);
|
| Wrong |
// construct a square and provide instructions for user
new FramedRect( 200, 200, 50, 50, canvas);
new Text("Clicking makes things happen...", 20, 20, canvas);
|
| Wrong |
new FramedRect( 200, 200, 50, 50, canvas);
new Text("Clicking makes things happen...", 20, 20, canvas);
// construct a square and provide instructions for user
|
| Right |
new FilledRect(55,50,50,5,canvas); // left eyepiece of glasses
new FramedOval( 50,50,60,50,canvas);
new FramedOval( 51,51,58,48,canvas);
new FilledRect(125,50,50,5,canvas); // right eyepiece
new FramedOval(120,50,60,50,canvas);
new FramedOval(121,51,58,48,canvas);
new FilledRect(105,70,20,5,canvas); // nose bridge
|
Comments are where they should be AND ...
|
|---|---|---|
| Wrong |
new FilledRect(55, 50, 50, 5, canvas); // top of left eye
new FramedOval( 50,50,60,50, canvas); // oval of left eye -- outter frame
new FramedOval( 51,51,58,48, canvas);// oval for the left eye -- inner frame
new FilledRect(125,50,50,5,canvas); // top of right eye
new FramedOval(120,50,60,50,canvas); // oval1 of right eye
new FramedOval(121,51,58,48,canvas); // oval2 of right eye
new FilledRect(105,70,20,5,canvas);// the bridge of glasses
|
|
| Wrong |
new FilledRect( 55,50, 50, 5,canvas); // left eye -top bar
new FramedOval( 50,50, 60, 50,canvas); // left eye -bigger oval
new FramedOval( 51,51, 58, 48,canvas); // left eye -inside oval
new FilledRect(125,50, 50,5,canvas); // right eye -top bar
new FramedOval(120,50, 60,50,canvas); // right eye -bigger oval
new FramedOval(121,51, 58,48,canvas); // right eye -inside oval
new FilledRect(105,70,20,5,canvas); // glasses bridge center
|
| Right |
// Casey Jones
|
|---|---|
| Wrong |
//Casey Jones
|
private static final int SUN_CORNER_X = 25;
paraphrasing Ch8, p.219 of your text...
General Guidelines:
- Instance Variable - Should be used if a value is necessary as part of an object's STATE.
- Formal Parameter - Should be used if a value is somehow useful but only in context and the client needs to be able to specify it.
- Local Variable - Should be used if a value can be initialized locally and that value is not necessary for later method calls.
The expanded reasoning on these guidelines can be found on the bottom half of p.219 of your text.
For example, the below is an excellent example of documentation. One line of documentation explains several statements. And does it well!
// construct three dice and directions for rolling them
die1 = new FramedRect(canvas.getWidth()/4, canvas.getHeight()/5, 50, 50, canvas);
die2 = new FramedRect(canvas.getWidth()/2, canvas.getHeight()/5, 50, 50, canvas);
die3 = new FramedRect(canvas.getWidth()*3/4, canvas.getHeight()/5, 50, 50, canvas);
msg = new Text("Click to roll dice", 20, 20, canvas);
Pay attention to what you are doing. It is possible that some sections of your source code are 'self-documenting'. This is likely when you have been thoughtful about your variable names.
Example - bad because it describes syntax of code:
private FilledOval moon; // declare variables
private FilledOval shadow;
private FilledRect nightsky;
private Text instructions;
Example - bad because it repeats code & adds no extra meaning:
private FilledOval moon; // filled oval that represents the moon
boxGrabbed = box.contains(p);
is much better than the following equivalent but awkward code.
|
if ( box.contains(p) )
boxGrabbed = true;
else
boxGrabbed = false;
|
if (box.contains(p))
new FilledOval(50,50,50,50,canvas);
is much better than the following equivalent but awkward code.
|
if ( box.contains(p) == true )
new FilledOval(50,50,50,50,canvas);
|
while ( !done ) {
. . .
}
is much better than the following equivalent but awkward code.
|
while ( done == false ) {
. . .
}
|
// Make inner circles as long as radius is big enough
while (r > 20){
. . .
}
is much better than the following equivalent but repetitive documentation.
|
// while loop for circles
while (r > 20){
. . .
}
|
while (radius > MINIMUM_RADIUS){
. . .
}
is much better than the following equivalent but ambiguous code.
|
while (r > 20){
. . .
}
|
for (int i=0; i < randomOvals.length; i++){
randomOvals[i].setColor(Color.RED);
. . .
}
-- or --
for (FilledOval nextOval:randomOvals){
nextOval.setColor(Color.RED);
. . .
}
is much better than either of the following (probably) equivalent but less-robust code fragments.
|
for (int i=0; i < NUM_OVALS; i++){
randomOvals[i].setColor(Color.RED);
. . .
}
for (int i=0; i < 10; i++){
randomOvals[i].setColor(Color.RED);
. . .
}
|
Unless assigment specifies otherwise, you must prompt user for input.
Unless assigment specifies otherwise, you must perform error checking.
When passing parameters, all should be used in the method in the most 'reasonable' and 'intuitive' way.
For example if a width parameter is passed it should be used for the whole width of something -- no more and no less.