CPSC 170 Spring 2005
Program 1: A Calendar System
Due Friday, Feb 4, 2005
Description
As a busy college student, you are finding it difficult to keep track
of all of your commitments -- classes, labs, club meetings, sports
practice, etc. Obviously, you need a calendar. But you know you'd
lose a paper calendar and you're too cheap to buy a PDA, so you have decided
to write your own. You figure you'll need at least the following features:
- Schedule an event -- Take the month, day, time, duration, and
description of an event and put it on the calendar. If this event
conflicts with another event go ahead and schedule it but issue a
warning message. Note that this means that multiple events can be
schedule in the same time block.
- Show a day's events -- Take a month and day and show all of
the events scheduled at each time that day. If no events are
scheduled for the day, issue an appropriate message.
For now you think a single year at a time is sufficient.
You also have a couple of preferences you want to build into the
system:
- You don't like to think in military time, so the system should use
AM and PM. (You're not alone; I once waited four hours for a train and then
missed it because I was interpreting 20:00 as 10:00pm instead of 8:00pm. Aaargh.)
- You think of months by name, not number, and want to enter them that way.
- Your typing isn't the best, so you want to be sure the system does
checks all of the input.
- You're a stickler for nice interfaces. Who wants to use a program that's
clumsy or hard to figure out?
Program Design
To fulfill the requirements above, you should write a Calendar class
with (at least) the following public methods:
- public String schedule(String month, int day, int hour, String ampm, int duration, String event) -- Takes the time, duration, and description of an event and puts it
on the calendar. Returns a string indicating the results -- "Scheduled" if
everything is ok, "Scheduled with conflict" if
the input is ok but there is a conflict, and a description message (e.g.,
"Error in month -- not scheduled") if there is an error in the input. Be
sure to check the following on the input:
- Hour is between 1 and 12, am or pm
- The month has at least 3 characters and they correspond to one of the
months (e.g., Nov).
- Duration is between 1 and 24 hours. If you wish, you can disallow
an event that carries over from one day to the next. If you allow this,
be sure you deal with it correctly.
You should be able to deal with upper or lower case in all input.
- public String getDay(String month, int day) -- Takes a month and
day and returns a string containing a listing of the day's events
by time, nicely formatted. Do not
include times for which there are no events. If there are no events for
the day, return an appropriate message.
Your methods must have exactly the interfaces given, as I will call them
using my driver.
A few implementation notes:
- You'll have to get organized about converting between user and internal
representations (between strings and ints for months, between military and
am/pm time for hours). Don't clutter your code with this; write methods
to do it and use them as needed.
- You should write a menu-driven test program that allows the user to
repeatedly add events and show the events for a day.
- You should represent the calendar using a 3-dimensional array with
month, day, and hour as the dimensions. Tailor the number of days (that is,
the length of the second dimension) to the month. This means that
the array will not be rectangular.
Extra Credit
Two possible extensions:
- Add a search feature that takes a string and returns a list of the
month, day, time, and events in which it occurs. Be sure that you return
only the relevant events, not others that happen to be scheduled at the same
time.
- Add a delete feature that deletes a scheduled event. Think about
a useful way to implement this.
What To Turn In
Turn in hardcopy of your code and submit your prog1 directory as you do your labs. Both are due by 4:00 on Feb 4.