| 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
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,
Date in the main BlueJ window.void main(args).OK.Here is an example of what the window for step 3 above looks like. Note that
the entered text is "2003", "9", "11"

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:
%) to determine the day of the week (as
a number)."Sunday",
"Monday", .... 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?
-- Laurie Williams |
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.