CSE 11 Spring 2001
Homework #2

Required reading: Savitch text Chapters 4 and 5.

Turn in due date: Thursday April 19 (i.e., 8 am April 20)
Interview due date: Tuesday April 24.

DO NOT turnin hw2 before April 14. You can do hw2 before then and even take an interview, just do not turn it in before April 14

Note: You can do this and take an interview without turning in the assignment, as long as it is before the turnin deadline (and until the deadline is announced it is definitely before the deadline).

Programming: You may work in teams of two students, but once you form a team, you cannot change the team for this assignment. You may work alone if you prefer.

If you want to start on this after reading only Chapter 4, and that is a good idea, then do Exercise 1 in Chapter 4. This one asks you to redo it using stuff from Chapter 5, but most of the code you produce doing it after Chapter 4 will carry over unchanged.

(This is similar to but not the same as Programming Project 2 in Chapter 5 of the Savitch text.)

Modify the definition of the class Species in Display 4.19/page 276 (and available in the public directory and on the CD that comes with the text.) by removing the method set and adding the following methods: (1) five constructors, one for each instance variable, one with three parameters for the three instance variables, and a default constructor; (2) four methods named set, which can reset values; one is the same as the method set in Display 4.19/page 276; the other three each reset one of the instance variables. Be sure that each constructor sets all of the instance variables. Then, write a test program to test all the methods you have added. Your modified definition of the class Species will be in a file named Species.java. Your test program will be in a file named SpeciesTester.java. After doing all this, do Programming Exercise 1/page 230 from Chapter 4 (A copy is below).

Exercise 1 Chapter 4 (modified for this assignment):
Write a program to answer questions like the following: Suppose the species Klingon ox has a population of 100 and a growth rate of 15%, and the species naked mole rat has a population of 10 and a growth rate of 35%. How many years will it take for the naked mole rat population to exceed the Klingon ox population? Use the class Species that you define. Your program will ask for the data on both species and will respond by telling how many years it will take for the species with the lower population to get a population that exceeds that of the species that starts with the higher population. The two species may be entered in any order. Note that it is possible that the species with the smaller population will never exceed that of the other species. In this case, your program should output a suitable message stating this fact.

What to turn in: You will produce three files, Species.java, SpeciesTester.java, and a program that solves Ex 1 in chapter 4 (call it Crossover.java). You turn in Crossover.java. Leave the other two files in your account and do not touch then so we can test the dates. Note: You are to use YOUR modified Species class to do Ex 1 in chapter 4. (It will not make much difference but may make a small difference from using the class Species in the book.)