It's for Jaque

taxi_1
programmingstyleguidelinesforjava.pdf

Programming Style Guidelines for Java Programming

The following document is intended to specify general programming style guidelines. The course

grader will use this as one reference when grading class projects/assignments/labs/tests. If you

have any questions about this style guidelines, please ask your instructor.

Please attend all lectures and labs, and read all materials provided for this course carefully

because style concepts and conventions are discussed in those venues.

General Principles

1. All identifiers must be meaningful, not extremely abbreviated. - Variables or constants are typically nouns, such as stockName or stock_name - Constants are typically all uppercase letters such as THRESHOLD - Functions names are typically verbs, such as PrintSomething()

2. The main function should not exceed two pages in length. Other functions should not exceed one page in length.

3. Declare numeric values that remain constant throughout a program as named constants using the final qualifier.

4. Nesting of any combination of if, for, while, do while, and switch statements should be less than 4 levels deep.

5. Variables and constants used only within a function are declared local to the function. 6. Global variables are not used unless it has to be used.

Comments / Internal Documentation

1. Every class must include a main header comment with the following format with Java Documentation Comments: /** PROGRAM <provide a meaningful program name here>

* AUTHOR: <your name>

* Project Number: <number>

* Due Date: <give date project is due>

* SUMMARY

* A brief description of what the program does.

* Usually one paragraph or so in length.

*/

2. Comment every identifier declared in a program For example,

private int curDate = 20130706; //current date

private String stockName = “”; //the name of a stock.

private final int MAX_NUMBER_STOCKS = 10; //maximal number of stocks tracked

3. Using Java single line comments and block comments appropriately

Formatting Program Source Code

1. Each statement must begin on a new line

2. Appropriate indentation is used in all code

3. The source code and comments on each line must appear in the first 80 or

fewer columns of the line.

4. One black space must appear before and after the assignment operator ‘=’

and the relational operators ‘==’, >, <, etc. Spacing is used to clarify many

equations.

For example,

sum = x + y; //this is good and clear

sum=x+y; //this is bad

5. Functions are separated from one another by using at least 5 blank lines.

For example:

private void PrintMessage(){

}

private int CalculateSum(int num1, int num2){

return 0;

}