Comp201: Principles of Object-Oriented Programming I
Spring 2008 -- HW 03   


See Schedule Page for due date!

Save all of your work in a directory called HW03 on your U: drive (Owlnet account) inside a directory called Comp201 .

You will need to use Full Java language level for this assignment.

  1. (25 pts total) Remember the class Person?  A Person has a birth date and knows how to compute the number months till his/her next birth day (click here to see the code again).  In this class Person, we use three integers to represent the birth day (_bDay), the birth month (_bMonth) and the birth year (_bYear)  In this exercise, you are to implement a class called SmarterPerson that not only knows how to compute the number months till his/her next birth day like Person can, but also knows how to compute the number of days from the first of the current year till his/her birth day (taking into account the leap year case).  Instead of using three integers to store the birth date, SmarterPerson uses a Calendar object as discussed in lab 03.  Below is the skeleton code of SmarterPerson.  You are to write the code for the methods as indicated.
    import java.util.*; // This is to make use of the Calendar class and GregorianCalendar class
                        // that come with Java.
    public class SmarterPerson {
        private Calendar _cal;    
        /**
         * Initializes _cal to a concrete GregorianCalendar that corresponds to the day, month 
         * and year given in the parameter list.
         * For example: new SmarterPerson(28, 2, 1945) will create a SmarterPerson object with 
         * birth date February 28, 1945.
         * @param day the birth day ranging from 1 to 31
         * @param month the birth month ranging from 1 to 12
         * @param year the birth year, a positive integer.
         */
        public SmarterPerson(int day, int month, int year) {
            // STUDENT TO WRITE CODE
    	// WARNING: the month number for the Calendar class ranges from 0 to 11.
        }    
        /**
         * Computes the number of months till the next birth day given the current month.
         * Must give the same answer as a Person object with the same birth month.
         * @param currentMonth an int ranging from 1 to 12 representing the current month.
         */
        public int nMonthTillBD(int currentMonth) {
            // STUDENT TO WRITE CODE
            return 0; // TO DO!!!
        }      
    
        /**
         * Computes the number of days from the first of the current year till the birth day.
         */
        public int nDaysFromNewYearToBD() {
            // STUDENT TO WRITE CODE
            return 0; // TO DO!!!
        }
    }
  2. (15  pts total) Write a JUnit test class for the SmarterPerson class you wrote in problem 1.
  3. (20 pts total) Design an interface called IPerson that represents the union of class Person and SmarterPerson.  Modify Person and SmarterPerson to implement IPerson .
  4. (45 points total) Using the Ballworld program shown in class, create the following new concrete ABall subclasses that are all to be in the ballworld package (i.e. put them in the lower ballworld directory and put the statement "package ballworld;" at the top of the code).
    1. Download the supplied code here and unzip it into your HW03 directory. It should create a main directory called "Ballworld" with a DrJava project file (ballworld.pjt) with two subdirectories, called src and classes.  In the src directory are two  packages: ballworld (lower case) and command.
    2. Open the ballworld.pjt project file using the Project/Open... menu in DrJava .  You may not modify the supplied code in any way to complete this assignment!
    3. (15 pts) ColorChangeBall -- whose color randomly changes every time it is updated.
    4. (15 pts) BreathingBall -- whose radius grows larger then smaller then larger then smaller, etc. each time it is updated.
    5. (15 pts) MyBall (use a different name -- call it sometime appropriately descriptive) -- does what ever you want it to do, so long as it is not the same as one of the existing balls. Be creative!

Hints -- these will be updated continuously as people ask questions. Check back often!:

105 pts total.

When you have completed your homework, zip up the entire HW03 directory and submit the zipped file to your Comp201 WEBCT account.

 

Grading criteria

  1. SmarterPerson - total 25 pts
  2. Unit test for SmarterPerson - total 15 pts
  3. The interface IPerson should have only one method: nMonthTillBD. 10 pts
  4. For parts c, d, and e:

 

 


Last Revised Thursday, 03-Jun-2010 09:50:22 CDT

©2008 Stephen Wong and Dung Nguyen