Project 4
Due Date: beginning of lecture, Tuesday, Oct. 14, 2003
The purpose of this assignment is to become
familiar
with conditional control structures.
Background
A calendar date consists of a month, a day of the month, and a year.
Many
programs must be able to handle dates, so it is useful to understand
how
such things are represented and manipulated.
In this project, we will represent a date as an
ordered
triple of integer values representing the month, day, and year, in that
order. To be a valid date, this triple must have four properties:
-
the month must be in the range 1-12, where January = 1 and December =
12;
-
the day must be in the range 1-31;
-
the year must be no earlier than 1753, the first full year of our
current
(Gregorian) calendar;
-
the month/day/year combination must form a valid date; that is,
-
the day can't be 31 in a 30-day month;
-
in February, the day can't be greater than 28 (non-leap year) or 29
(leap
year).
A year is a leap year if it is divisible by 4 but not by 100.
Exceptionally,
a year that's divisible by 400 is a leap year. (ASIDE: one
aspect
of the "Y2K problem" of the year 2000 is that many programs failed to
recognize
this exception, and treated 2000 as a non-leap year!)
Project
Develop a program that will
-
prompt the user to enter a month, a day, and a year;
-
validate the date according to the properties above;
-
if the date is invalid, display an appropriate message and end the run;
-
if the date is valid, display a message that indicates the day of the
week
on which that date occurs. An example of the message might be
The date is valid and occurs on Thursday.
To find the day of the week, you can import the class csci53.DateOps,
which contains the following method. A program that demonstrates this
is
DayTest.java.
You can copy both from programs53 into your
csci53 directory.
//
-----------------------------------------------------------
// Finds the day of the week for a given date.
// Sunday = 0, Monday = 1, etc.
//
// Assumes its arguments are valid and form a valid date.
// Calculates correct results for dates in the Gregorian
// calendar, after September 1752.
//
// This code is adapted from a C version that appears at
// http://www.eskimo.com/~scs/C-faq/q20.31.html
//
// The algorithm is a table-driven adaptation of the famous
// Zeller Congruence; for more details, see
// http://www.merlyn.demon.co.uk/zeller-c.htm
//
-----------------------------------------------------------
public static int dayOfWeek(int month, int day, int year)
This method returns a numerical value for the day. Your program will
have to determine which day name to display as a string.
Use if statements for the date validation and a switch
statement for displaying the day name.
What to submit:
You must follow the process given in Systematic
Software Development and the sample project packet distributed
in class.
Your grade will be calculated on a 20-point basis, as follows:
-
6 points -- analysis and design (including algorithm in structured
English)
-
4 points -- test plan
-
6 points -- correct execution of program according to test plan
-
4 points -- layout and style of program source code
Extra credit:
We'll continue the 2-point bonus for getting an early start. If you
e-mail
your "framework" listing file to Prof. Feldman, and the time stamp on
the
e-mail is no later than 5 PM, Friday, Oct. 10, 2003, you will be
awarded
2 extra project points. The "framework" must be a listing (.txt)
file, with no compilation errors or warnings, that contains the
declared
variables, and a set of comments inserted for the main algorithm steps.
MBF 10/1/03