CS1027b Computer Science Fundamentals II

Lab 2

General lab instructions to help labs run smoothly

Overview and preparation

In this lab you will work with your own classes, and Javadoc. Upon completion of this lab, you should be able to do the following:

Make sure that you show the result(s) of each Exercise to your TA and that you submit the .java files your wrote through owl, to get your marks for the lab.

Preparation. Make sure you understand the parts of a class definition: instance variable declaration, constructor definition, method definition. Read this introduction to Javadoc.

Exercise 1: Adding a Test Harness to the Person class

To make it easier to test code that you have written for a Java class you can add to that class a main method that acts as a "test harness". A test harness is a main method that includes calls to methods that you wish to test. For convention this main method is the last method of the class.

If you have a test harness, you do not need to have a separate application program in order to test your class: the test harness is part of the class you are testing. In this part of the Lab, you will get some experience in writing a test harness.

Exercise 2: Adding Methods to the SocialNetwork Class

Exercise 3: Using Javadoc comments

Exercise 4: Using the SocialNetwork Class in an Application

Make sure you show your results to the TA, and submit your code on owl.