COMP 2100 Lab Exercise 1: Warm-up Nim exercise
(15 points + possible 2 point bonus)
Turn in before the next lab period.
Reading the Pile specification, you'll notice that all the methods contain either a "Precondition:" expression, a "Postcondition:" expression, or both. The precondition expression is a condition that the method expects to be true at the time that method is called. The postcondition expression is a Boolean condition that the method guarantees to be true when the method is finished, assuming the precondition is met. Preconditions and postconditions are foundations for programming by contract.
When testing your Pile methods, be sure to try them with argument values that do not meet the precondition. What is the result?
Do your best to comment your code with Javadoc-style comments that attempt to match the
comments on the Pile class API. To preview a javadoc-produced page in jGRASP, click
the open-book icon located left of the compile
icon. "Precondition" and "Postcondition" are not
Javadoc tags but you can format them by marking them up with standard HTML tags - this is left
as a bonus.
Javadoc is a utility included with the Java compiler that produces API documentation based on specially-formatted comments in Java source code files. When you read Java library documentation such as the Java 2 Standard Edition 7 API Specification, you are reading HTML documents (web pages) produced by Javadoc.
Javadoc comments are placed above the component they describe. Comments describing a class are placed just above the start of the class definition. Comments describing a method are placed just above the method definition.
A Javadoc-style comment starts with "/**" on a line by itself and ends with "*/" on a line by itself. The comments placed between them represent descriptions and tags.
Example Javadoc tags:
@param
is used to describe one parameter of a method
@return
is used to describe the return value of a non-void method
Example method with Javadoc-style comments
/** * Method to return the greater of two integer values. * @param first an integer value * @param second another integer value * @return The greater of the two parameter values */ public int greater ( int first, int second ) { return (first > second) ? first : second ; }The HTML produced by this specification is displayed as:
greaterpublic int greater(int first, int second)
|
As stated above, Javadoc does not define tags for Precondition and Postcondition! One way to include them is to format them using HTML within the Javadoc comment. Javadoc will pass any HTML code through without modification. This is left as a bonus.
You don't need many different tags to produce Javadoc-style formatting. These should
be enough to get you started:
Tag | What it does |
---|---|
<em> </em> | Render enclosed text in italics |
<strong> </strong> | Render enclosed text in bold |
<p> </p> | Render enclosed text as a new paragraph |
<tt> </tt> | Render enclosed text in a constant width font |
<br> | Insert a line break at this point |
Another approach is to study the HTML source produced by Javadoc for the param and return tags and reproduce it. Those HTML tags will differ from the ones shown here. There is more than one way to mark up text to achieve a given visual result.
component | max points |
---|---|
Constructors | 3 |
Methods | 9 |
Identification (name, date, course) | 1 |
Basic javadoc (parameter, return) | 2 | Advanced javadoc (precondition, postcondition) - bonus | 2 |