Assignment 2: Creating Classes

Objective: Create Basic Java classes.

Due: Before the next class (Monday).

Set Up

Create a directory for assign2 within your cs209 directory.

Part 1: Fixing A Program

Save Assign2.java into your assign2 directory.

This program contains at least 5 errors. Some are compiler errors that the compiler will catch. Others are logic errors that you need to catch. One is an access modifier error that is not good OO style.

Comment out the original code and note the cause of the error. Then, correct the code.

After you're sure the program behaves correctly, save the output in a file called debugged.out.

Part 2: Creating a Birthday Class

Create a Birthday (but not birth date) class. The state of the class should be the month and day.

There will be two separate constructors for the Birthday class. (Whoa! We couldn't do that in Python! We have already seen examples of multiple constructors, e.g., in the java.util.Random class. We'll talk more about why we can do this on Monday, and I hope from this assignment, you'll have your ideas of why this is possible.) One constructor will take as parameters the month and date. The other constructor takes no parameters and randomly generates the birthday (the month and date).

To create the random birthday, you will probably need a static array of integers representing the number of days in a month. (For this assignment, assume that February has 29 days.) Also, you want only one random number generator for the whole Birthday class to ensure the best random number generation.

The methods of the class should be getting and setting the month and date.

The main method for the class should test your Birthday class, including creating objects using both constructors. Don't just rerun the program a bunch of times, changing the code and recompiling and running. Have all the tester code in this method.

Pay close attention to the access modifiers you use for the state and methods.

This problem is "underspecified", e.g., I'm not saying how to represent the month and day. I'm leaving that up to you. The problem also doesn't seem like one of my normal problems... We're building to something.

Save the output of your program in birthday.out

Turning in Your Assignment

As usual, copy your assign2 directory into your turnin directory, i.e., /home/courses/cs209/turnin/yourusername.

There is no printed part of this assignment.

Grading (100 pts)

You will be evaluated based on