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

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

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.