CS220, Claude Anderson, Spring 2002
Cal Programming Assignment
Assigned: Friday, 14 March 2002
Due: Thursday, 21 March 2002, 2:00 PM
You may do this assignment alone or with one other person.
If you'd like to do it with a partner but do not know who to work
with, let me know. If two people are in that position, I will let
each of you know that so that you can decide whether to work together.
Overview
You will write a Java application that duplicates some of the functionality of
the UNIX cal command. When called with one numeric argument,
the command displays a calendar for the indicated year. It should
work for any year after 1799. For example:
> cal 1800
1800
Jan Feb Mar
S M Tu W Th F S S M Tu W Th F S S M Tu W Th F S
1 2 3 4 1 1
5 6 7 8 9 10 11 2 3 4 5 6 7 8 2 3 4 5 6 7 8
12 13 14 15 16 17 18 9 10 11 12 13 14 15 9 10 11 12 13 14 15
19 20 21 22 23 24 25 16 17 18 19 20 21 22 16 17 18 19 20 21 22
26 27 28 29 30 31 23 24 25 26 27 28 23 24 25 26 27 28 29
30 31
Apr May Jun
S M Tu W Th F S S M Tu W Th F S S M Tu W Th F S
1 2 3 4 5 1 2 3 1 2 3 4 5 6 7
6 7 8 9 10 11 12 4 5 6 7 8 9 10 8 9 10 11 12 13 14
13 14 15 16 17 18 19 11 12 13 14 15 16 17 15 16 17 18 19 20 21
20 21 22 23 24 25 26 18 19 20 21 22 23 24 22 23 24 25 26 27 28
27 28 29 30 25 26 27 28 29 30 31 29 30
Jul Aug Sep
S M Tu W Th F S S M Tu W Th F S S M Tu W Th F S
1 2 3 4 5 1 2 1 2 3 4 5 6
6 7 8 9 10 11 12 3 4 5 6 7 8 9 7 8 9 10 11 12 13
13 14 15 16 17 18 19 10 11 12 13 14 15 16 14 15 16 17 18 19 20
20 21 22 23 24 25 26 17 18 19 20 21 22 23 21 22 23 24 25 26 27
27 28 29 30 31 24 25 26 27 28 29 30 28 29 30
31
Oct Nov Dec
S M Tu W Th F S S M Tu W Th F S S M Tu W Th F S
1 2 3 4 1 1 2 3 4 5 6
5 6 7 8 9 10 11 2 3 4 5 6 7 8 7 8 9 10 11 12 13
12 13 14 15 16 17 18 9 10 11 12 13 14 15 14 15 16 17 18 19 20
19 20 21 22 23 24 25 16 17 18 19 20 21 22 21 22 23 24 25 26 27
26 27 28 29 30 31 23 24 25 26 27 28 29 28 29 30 31
30
Once your Cal class is written, the command
> Java Cal 1800
should produce exactly the same output.
Objectives
- Practice with arrays, computation, and program
organization.
- Development of the logic of a non-trivial algorithm.
- Getting deeper into the use of the parameters of methods
- Programming to meet a very precise specification.
Tools
Most assignments in CS 120 and 220 involve discovering and using
tools that are part of the JDK API libraries. Fo rthis assignment,
you are to use only the basic language tools: primitive types, arrays,
strings, System.out, and methods that you write. You probably need
only one class, and all methods can probably be static. In short,
this assignment is about algorithms, not about interacting objects.
IN particular, you are not allowed to use GregorianCalendar or
any other class that is specifically designed to deal with dates. For
this assignment, you must do it all yourself.
In JCreator, when you create the project, select "Empty Project".
Add the Cal class after the project has been created.
Detailed specifications
-
The application's class must be called Cal.
-
The application should expect one command-line argument, which is a
string representing the number of a year that is later than 1799.
-
Output Specification:
- Exactly 40 lines of output, all sent to System.out.
- The first three lines are empty.
- Line 4 contains four tab characters, followed by the year.
- Line 5 is empty.
- Lines 6-37 contain four groups of eight lines each; each group of
eight represents three months.
- The first of the eight lines contains:
- a tab
- a space
- a three-letter month name
- three tabs
- a three-letter month name
- two tabs
- seven spaces
- a three-letter month name
- the second line contains three sets of seven
day names, each right-justified in a
two-character field and separated by a single
space.
The sets of seven are separated by two
spaces.
- the last six of the eight lines consist of
the days of the months, spaced like the day
names in the previous part. It is possible (but
rare) for the sixth line to be completely
blank.
- Lines 38-40 are empty.
Challenge:
Can you do this efficiently without using any 2D arrays (or
their equivalent), and only using a small number of one-dimensional arrays?
Turnin
Make a folder in your turnin folder called Cal. All of your java
source files should be directly in that folder, not in some
soubfolder(s). Your main method should be a class called Cal.