Getting the computer to understand your program is no guarantee that people will be able to follow it. Just as you would edit an English composition, you should spend time revising a computer program to make it elegant and readable. The following guidelines will help you write programs that are easy to read and modify. Beginning with Lab 2, the CS101 graders will expect your assignments to conform to these style and documentation conventions.
width
instead of w
.
(However, if an assignment specifies a particular name, please don't choose
a different one.)
GOOD STYLE: | BAD STYLE: |
---|---|
return (height >= level); |
if (height >= level) return true; else return false; |
int caloriesFromFat = 18;
public class VelocityVector {
public final double PI = 3.14159;
public static boolean withdraw (int requestedAmount) { if (balance < requestedAmount) { return false; } else { balance = balance - requested amount; Terminal.println("Withdrawl of $" + requestedAmount + " successful, leaving $" + balance + "."); return true; } }
toString
method
if (xPosition < xLeft) // left of box ... else if (xPosition > xLeft + width) // right of box ... else if (yPosition < yBottom) // below box ... else // inside or above box ...
int RectangleWidth = 30; // the width of the rectangle is 30