0% found this document useful (0 votes)
4 views16 pages

Comp Tutorial - 1

The document outlines a tutorial for COMP 249, focusing on Object Oriented Programming II, with exercises related to a rectangle class and a Student class that tracks grades. It includes coding exercises, Java comments types, and an introduction to Javadoc for documenting Java programs. Additionally, it provides guidelines for generating documentation and includes examples of Javadoc comments for classes and methods.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views16 pages

Comp Tutorial - 1

The document outlines a tutorial for COMP 249, focusing on Object Oriented Programming II, with exercises related to a rectangle class and a Student class that tracks grades. It includes coding exercises, Java comments types, and an introduction to Javadoc for documenting Java programs. Additionally, it provides guidelines for generating documentation and includes examples of Javadoc comments for classes and methods.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

COMP 249:

Object Oriented
Programming II
Tutorial 1:
Review of COMP248 and Javadoc
Question 1
Assume a rectangle class with two attributes, a and
b representing the size of the rectangle. What is the
output of this code,
Question 2
What is the output of this code, assuming previous
rectangle class:
Question 3: Consider these two classes
Question 3:
What would be the output of:
Question 4: Coding exercise
Write a Student class which keeps track of grades and
generates a final mark.
You should store:
 3 quiz scores, an array of int between 0 and 20;
 1 midterm score, an int between 0 and 50;
 1 final score, an int between 0 and 100;
 the overallScore (double) and letter grade (char).

also create the appropriate accessor and mutator methods.


Question 5: Coding exercise (cont’d)
Student should also include the methods:
public void calculateOverallScore() { … }
Quizzes are worth 15% of the grade,
Midterm is worth 35% of the grade,
the Final is worth 50% of the grade.
public void finalLetterGrade() { … }
100 ~ 90: A 70 ~ 80: C 0 ~ 60: F
90 ~ 80: B 60 ~ 70: D
Comments in Java
3 types of comments in Java:

 // single line comments

 /* Multiple lines comment.


Useful to "erase" a block
of code from compilation */

 /**
* JavaDoc comments
* Can be used to generate html documentation
*/
Javadoc: what is it?
 A standard for documenting Java programs
 A system which allows to attach descriptions to classes,
constructors, fields, interfaces, and methods, in a
generated HTML document.
 This is done by placing appropriate comments directly
before the declaration of the item they describe:

/**
* The Student class implements methods to
* calculate a student’s grades
*/
public class Student { … }
JavaDoc: generating documentation
 In Eclipse
JavaDoc: generated documentation
JavaDoc: general form
/**
* One sentence ending with a period describing the
purpose.
* Additional lines giving
* more details (html tags can be included)
*
* javadoc tags to specify more specific information,
* such as parameters and return values for a method
*
* @Tag Description ...
* @Tag Description ...
*
*/
Javadoc: Some tags
Tags are used to specify specific information in the HTML
documentation.
Some common tags:
 For files, classes, and interfaces:
 @author name
 @version number
 For methods:
 @param name description
 @return description
 @exception exceptionClass description
 @deprecated description
 For everything:
 @see relatedReference (ex. other class name)
Javadoc: Simple example
Here’s a simple JavaDoc comment describing a class:

/**
* The Foobar class does things.
* Amazing things, in fact.
*
* @author Bob
* @version 1.1
* @see String
*/
public class Foobar { … }
Javadoc: Simple example
Here’s a simple JavaDoc comment describing a method:

/**
* Takes two integers and uses them to make the
* calculations.
*
* @param firstValue an integer value
* @param secondValue another integer value
* @return a double calculated from the two values provided
*/
public double makeCalculations(int firstValue, int
secondValue) { … }
Question 6: Javadoc
Go back to your Student class and add Javadoc comments for
each of your classes and methods, compile the
documentation and take a look at the result.

You might also like