|Fourth Java Assignment: Calendar
CIT 591, David Matuszek, Fall 2001
So far, your assignments have each involved a lot of new ideas. Much of programming is just "bookkeeping"--keeping track of things. The purpose of this assignment is not to introduce a bunch of new ideas, but rather to give you some additional practice in handling the routine chores. Almost no use is made of class and object concepts.
In this assignment, given a year (such as 2001), you will write an application to print out a 12-month calendar for the year. Your calendar should look something like this:
January 2001 S M Tu W Th F S 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 February 2001 S M Tu W Th F S 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
...and so on.
Some of the things you need to do are:
(This list probably isn't complete.) Like I said, a lot of bookkeeping.
An important principle in designing methods is that each method should do one
simple, easily defined thing, rather than a potpourri of things. In this program,
you are to write one or more additional methods (besides
I can easily think of three separate things that each need to be done twelve
times; these could be three separate methods, or combined into two or one methods.
I can think of another thing that needs to be done approximately 365 times;
perhaps this should be a method. Methods should be chosen and named in such
a way as to make the program easier to read.
By the way, this program makes almost no use of objects. Your methods should
probably all be
You do need to use a few new things. You probably already know that an application requires at least this method:
public static void main(String args)
When you run your application, in the BlueJ dialog box that pops up, enter a year number as a string (that is, quoted) within the braces. Like this:
To retrieve this value, use:
year = Integer.valueOf(args).intValue();
You also need to figure out on which day of the week the year begins. This
is extremely complicated; let Java do it for you. You should have the Java API
documentation on your hard drive in some location resembling
open it. (If not, find it on the web at
All Classes, look up the
You'll find a possibly interesting discussion of the complexities of the package,
but somewhere below that you'll find what you want. (Hint: Create a
set a date, look at a variable.)