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. The CSE131 TAs will expect your assignments to conform to these style and documentation conventions. We will be grading your labs partly on style, so don't assume that it's good enough to just get your program running. Read this Style Guide carefully, and let us know if you have any questions.
/** * Deposits the given amount into the account. * REQUIRES: The given amount is positive. * @param amount the dollar amount to deposit * @return the new balance */ public int deposit(int amount) { if (amount < 0) throw new IllegalArgumentException("positive amount required"); balance += amount; return balance; }In all comments, be brief and informative. Since the CSE131 TAs are already familiar with the assignment, please don't repeat the details of the assignment. Instead, communicate your approach to solving the problem.
Note: You do not need to write Javadoc comments for your JUnit test methods, but some inline comments may be necessary to explain what case the particular test is checking, if it's not immediately obvious from the test code itself.
width
instead of w
.
(However, if an assignment specifies a particular name, please don't choose
a different one.)
static final int BRUSH_SIZE = 5;This not only makes it easier to read the program, but also simplifies changing the values later because you only have to make the change in one place, where the constant is defined. (Test cases are an exception--use numbers there.) Rule of thumb: if a constant is used more than once, give it a name.
int caloriesFromFat = 18;
public class DirectionVector {
public static final double PUPIL_FRACTION = 4;
public static boolean withdraw (int requestedAmount) { if (balance < requestedAmount) { return false; } else { balance = balance - requested amount; System.out.println("Withdrawl of $" + requestedAmount + " successful, leaving $" + balance + "."); return true; } }
TIP: Eclipse will help correct your indentation. Select the section of the file you want to correct, and then choose "correct indentation" from the "source" menu.
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