CS1027b Computer Science Fundamentals II

Lab 2

Learning Outcomes

Upon completion of this lab, you should be able to do the following:

General lab instructions to help labs run smoothly

Overview and preparation

IMPORTANT. Make sure you attend the lab session to which you registered, show the result(s) of each exercise to your TA, and submit the .java files that you wrote through OWL by 11:55pm on the same day as your lab session to get your marks for the lab.

Preparation. Read this introduction to Javadoc.

Exercise 1: Comparing Objects

Exercise 2: Adding a Test Harness to the Person class

A program might consist of several Java classes each one invoking methods and accessing data provided by other classes. Once you have written a Java class, you should test all methods in it to make sure they work as they are supposed before adding that class to the program and allowing other classes to interact with it. Since the execution of a Java program always starts at a method called main, to test in isolation the methods of a class we can temporarily add to that class a main method that acts as a "test harness". A test harness is a main method where you add calls to methods that you wish to test. For convention this main method is the last method of the class.

Exercise 3: Simple Java application using Strings

Exercise 4: Using Javadoc comments