Lab #3

 

Course

Instructor

CSC 101 - Spring 2003

Clark S. Turner

Fundamentals of Computer Science I

Email: csturner@csc.calpoly.edu

Website: http://www.csc.calpoly.edu/~csturner

Office: 14-211

Phone: 756-6133

                      

Objectives

  1. Run Java Tutorial
  2. Add your own header and comments

Run Java Tutorial

This lab has an unusually high amount of reading, because it is important that you understand object-oriented concepts before attempting to program in Java.  You will read only the sections that describe objects, messages, classes, inheritance, and interfaces.  At the end of the section there are exercises to complete.  You will be asked to download two files called ClickMe.java and Spot.java.  You will make modifications to the files per instructions in the tutorial and test the program as you did in Lab #1.  You do not yet have enough experience with Java to understand the code, so I expect you to have trouble making the modifications.  Do not hesitate to look at the answers to the exercises at the end of the tutorial.  Feel free to experiment with different colors and spot sizes if you want.

 

 Now click on: http://java.sun.com/docs/books/tutorial/java/concepts/index.html

 

Add your own header and comments

Most of the programming concepts in the ClickMe.java and Spot.java files are more advanced than the material we have covered in class, but do your best to understand how the program works.  To the best of your ability, create meaningful comments before each class and method declaration in ClickMePurple.java and Spot.java.  Assume the reader does not understand java and must have enough information to use the class or method.  Trust me -  this is a useful and important practice.  The better your comments, the easier it will be for you to understand your own work after you have been away from it for a while.  The following header goes before the line “public class ClickMePurple extends Applet implements MouseListener {.“  You will be required to create a header like this at the top of all programs in the future. (You might want to learn to cut/paste it.)  You will learn about @author and @version tags when we cover the subject of Javadocs.

 

/**

 * Lab #2 - ClickMePurple from Sun's Java Tutorial

 *

 * Write a description of the program here.

 *

 * @author  your name

 *          CSC 101 – your section

 * @version  today’s date

 */

 

Note that javadoc comments begin with /** and end with */.  If you want to add comments near a line or section of code, use “//” immediately before the comment.  Before each method, create a comment similar to the example below.  If the method has parameters (inside parentheses), use the @param tag.  If the method contains a return statement, use the @return tag. For example, the square method below has one parameter 'x' and it has a return statement.

 

      /**

       * Describe what the method does.

       *

       * @param  x the integer that will be squared

              * @return the value of x squared

       */

                 public int squareX(int x) {

            return x*x;      //square operation

        }

 

 

If good commenting behavior becomes a habit in CSC101, you will save time for yourself and your colleagues in the future.

 

 

LAB EXERCISE # 3 is due by the end of the Thursday lab session.