Lecture 6 Documentation boolean conditions Textbook Chapter 2
Lecture 6: Documentation, boolean conditions • Textbook: Chapter 2, Chapter 5. 10 • Recap: – Local variables vs. fields vs. parameters (scope, life time) – Different arithmetic operators in java – What is modulus operator?
Increment (++) and Decrement (--) operator X = X + 1; X++; There is also ++X; X = X-1; X--; There is also --X;
Operator precedence • () • */% • +-
Interface vs implementation The documentation includes • the name of the class; • a general description of the class; • a list of constructors and methods • return values and parameters for constructors and methods • a description of the purpose of each constructor and method the interface of the class
Interface vs implementation The documentation does not include • private fields (most fields are private) • private methods • the bodies (source code) for each method the implementation of the class
Reading class documentation • Documentation of the Java libraries in HTML format; • Readable in a web browser • Class API: Application Programmers’ Interface • Interface description for all library classes
Writing class documentation • Your own classes should be documented the same way library classes are. • Other people should be able to use your class without reading the implementation
Basic Elements of a Class • Here are three basic elements of class definitions: public class Class. Name { Fields Constructors Methods } The contents of a class
Documentation for a class should include: • the class name • a comment describing the overall purpose and characteristics of the class • a version number • the authors’ names
javadoc Class comment: /** * The Responder class represents a response * generator object. It is used to generate an * automatic response. * * @author Michael Kölling and David J. Barnes * @version 1. 0 (1. Feb. 2002) */ public class Responder { … }
The documentation for each constructor and method should include: • • the name of the method the return type the parameter names and types a description of the purpose and function of the method • a description of each parameter • a description of the value returned
Making choices: If Statements ‘if’ keyword boolean condition to be tested - gives a true or false result actions if condition is true if(perform some test) { Do the statements here if the test gave a true result } else { Do the statements here if the test gave a false result } ‘else’ keyword actions if condition is false
Logical Operators ( ||, &&, !) Statement 1: If balance is greater than 0 AND price is greater than 0. if ((balance >0) && (price >0)) Statement 2: If balance is great than 0 OR price is great than 0 if ((balance >0) || (price >0)) Statement 3: If price is not positive if ( !(price >0))
- Slides: 13