CSci 2101 Lab 4. ArrayList and writing your own classes.

The lab is done in pairs.

Due Monday, September 26th at 11:59pm (by e-mail)

Total: 25 points

ArrayList exercise (15 points)

Exercise on ArrayLists on the resources page. Consult the description of ArrayList for array list methods.

Writing methods of objects (10 points)

Use the code for Person class and its testing code. Add and test the following methods of Person class:

  1. Two fileds, city and state, that store the city and the state of where the person lives. Do not change the constructor.
  2. A setCityState method that takes two strings (city and state) and sets the corresponding fields of the Person object.
  3. A method getAddress that will return the city/state where the person lives.
  4. A method livesInTheSameCity which takes another Person object and returns true if this person lives in the same city and state as the other person and false otherwise.

Extra credit: is there anything wrong with this method? (4 points)

Imagine you have just started working in a software development company, and your boss asks you to take a look at some code written by your predecessor at the company. Your boss says that the company software occasionally outputs unexpected results, and the method isOdd may be to blame. Unfortunately, the actual data ran by the client requires security clearance which you don't yet have. Because of that you don't know what data causes problems and whether it is related to the method isOdd. You are asked to test the method and report back on whether the method is correct, and if it's not then to explain what is wrong with it and fix it. Make sure to fix it in a good programming style (if a fix is indeed needed). Make sure to include all your test data in your report.
Below is the code:


public class IsVeryOdd {
    public static void main(String [] args) {
	// your test code goes here
    }

    /** The method takes an integer n and returns true if 
	n is odd and false otherwise
     **/
    public static boolean isOdd(int n) {
	return ( (n % 2) == 1);  
    }
}

How to submit

Submit the java file(s) by e-mail to me. The subject of the message must be 2101 Lab 4. Make sure to CC your group partner.


CSci 2101 course web site.