CIT 591 Assignment 1: Day of week
Fall 2003, David Matuszek

Purposes:

The general idea:

Given a date (year, month, day), find and print out the day of the week on which it falls. Your program should work for all dates after 1752 (the most recent calendar reform), as well as all future dates. Print the result in this form:

September 11, 2003 is Thursday

You should also print out the names of both authors (in addition to having them in the comments.)

Technical details:

Your program will consist of a single class. Name your class Date. It must, of course, have a public static void main(String args[]) method.

Your program would not be very useful if you had to specify, in the code, which date to use. Instead, you will supply the year, month, and day of the month in that order when you run the program. To do this,

  1. Right click on Date in the main BlueJ window.
  2. Choose void main(args).
  3. Enter the year, month, and day, in that order. Each number must be enclosed in double quotes, separated by commas. (See below.)
  4. Click OK.

Here is an example of what the window for step 3 above looks like. Note that the entered text is "2003", "9", "11" although the text field is a little too small to show it all (part of the first double quote is cut off).

The following "magic lines" will get these numbers into your program:

        year =  Integer.valueOf(args[0]).intValue();
        month = Integer.valueOf(args[1]).intValue();
        day =   Integer.valueOf(args[2]).intValue();

You may use any and all Java that you know except the classes that deal with dates and calendars (you have to do the logic yourself!). For example, if you know about the switch statement, it might be more handy than nested if statements (but either can be used.)

Here is one possible approach:

Your program will need to know about leap years. A year is a leap year if (1) it is divisible by 4, but (2) not divisible by 100, unless (3) it is also divisible by 400. Thus, for example, 2000 was a leap year (divisible by 4, 100, and 400).

Here is a program skeleton that you can use to get started (copy and paste):

/**
 * Given a date (year, month, day), finds and prints out the day of the
 * week on which it falls.
 * 
 * @author (Put one of your names here--no parentheses)
 * @author (Put the other name here)
 * @version 1
 */
public class Date {
    
    public static void main(String[] args) {
        int year;
        int month;
        int day;
        
        // The following lines get the year, month, and day
        year =  Integer.valueOf(args[0]).intValue();
        month = Integer.valueOf(args[1]).intValue();
        day =   Integer.valueOf(args[2]).intValue();
        
        // Compute day of year (1..366)

        // Find day of week

    }     
}

What is pair programming?

Two programmers working side-by-side, collaborating on the same design, algorithm, code or test. One programmer, the driver, has control of the keyboard/mouse and actively implements the program. The other programmer, the observer, continuously observes the work of the driver to identify tactical (syntactic, spelling, etc.) defects and also thinks strategically about the direction of the work. On demand, the two programmers can brainstorm any challenging problem. Because the two programmers periodically switch roles, they work together as equals to develop software.

-- Laurie Williams
North Carolina State University Computer Science

In case you are interested, a good article on Pair Programming (in Adobe Acrobat format) can be found at http://collaboration.csc.ncsu.edu/laurie/Papers/Kindergarten.PDF.

Due date:

Your program is due before midnight, Thursday September 18. Zip up all files (.java, .class, and any extra files produced by BlueJ, such as .pkg and .pkh files), and submit via Blackboard. Please turn in one program for your pair, that is, you and your partner should not both turn in a copy.