CS110 Introduction to Computing
Spring 2006
Assignment#7: Birthday Numerology
Due in class on Tuesday, April 25, 2006
There is no credit for late work.
What to do: Write
a Java program that inputs a person's date of birth (month, day, year):
- Informs the
person if the year of birth is a prime number.
- Informs the
person if the year of birth is a leap year.
- Computes
and outputs the day of week they were born.
- Computes
and outputs their Zodiac sign.
- Computes
and output the name of the Chinese year when they were born.
- Computes and
prints the person's age.
- Computes and
prints the number of days the person has lived so far.
- Wish
the person a "Happy Birthday!" if it is their birthday.
Do
only one of the ones written in green.
Algorithms for
some of the above computations will be discussed during lectures. Feel free
to use the web to search for answers to these exercises, not necessarily
the Java code, which will be your own
Some useful
pointers and hints:
- Days in
a month: Some Basic Information about calendars -- we know the number
of days in the month from this simple poem:
30 days hath September,
April, June and November,
All the rest have 31,
Except February which has 28
And in leap year 29.
It is simple enough to write some if-else statements (or a switch) that compute
the number of days from the month number given. This will be helpful for
figuring out the number of days a person has lived.
- Leap Years: Leap
years are determined by seeing if the year number is evenly divisible by
4 (good use for your remainder (%) operator). For century years, the number
has to be evenly divisible by 400, so 2000 was a leap year, 1900 was not.
- Prime Numbers: A
prime number is one which is evenly divisible only by itself and 1. The
slow way to figure out if a number is a prime is to have a loop which tests
every number from 2 up to the number itself (minus 1). If there are no
even divisors, then the number is prime. Computer people find prime numbers
very useful in cryptography.
- Current
Date & Time: There is a time function that can be used to get
the current date and time from a Java program. Since it uses your computer's
system clock information, be sure that is set correctly on the machine
you are using. Information about the date and calendar functions can
be found in your Lab Manual (handout given in class). You can use these
methods, or have the user input the current date after they input their
birthday.
The calendar is
the subject of many informative pages on the web, and the formulas we are
asking you to program for this assignment can be found (even including code
examples in some cases) through some surfing. Use the information links below
to the pages indicated for some descriptions that we thought would be helpful.
You can also use any other sources to get further explanation, but be sure
to reference any pages that you use as comment lines containing the web site
location (URL) as a footnote along with your code (note that your HTML file
does not need to link to the URLs you reference). For surfing, it is helpful
to be a bit descriptive in your search string -- I used "calendar day
of week" in google.com and found
a lot of helpful sites.
- Day of week: This
calculation is known as the Doomsday algorithm and has been popularized
by John Conway, a Princeton University Math Professor, who enjoys doing
this calculation for any date quickly in his head. You are only responsible
for the formula working for years in 19xx and 20xx. The calculation is
described at http://quasar.as.utexas.edu/BillInfo/doomsday.html Parts
2 and 3 are the sections you need to look at. The JavaScript code (which
is NOT Java, but a lot of it can be taken and converted into Java, if you
do some editing) for the formulas can be viewed with View Source in your
browser.
- Chinese
Calendar: The Chinese calendar is very complex, but for this assignment
we have simplified your task by just using the Western year. There are
12 animal symbols, the years go in a cycle, so you can just pick a year
(like 2006 is the Year of the Dog) and compute forward or backward to
figure out which animal a particular year happens to be. By tradition,
there are personal characteristics conveyed by each animal. Your program
needs to only give the animal name, but you could (for extra credit)
add a small description also. The sequence of animal names can be found
on a colorful page at: http://www.new-year.co.uk/chinese/calendar.htm If
you click on the animal names on that page, you will get each description
for that animal, which you can modify and use (optionally) in your program.
- Zodiac Signs The
Astrological calendar is also a bit complicated to compute accurately,
because it deals with the motion of the sun and planets through the star
constellation groups. Here again we will use more simplistic day range
calculations in order to determine which of the 12 signs to select. You
can find the days to use for your calculation on a fairly elaborate website
at: http://www.elore.com/Astrology/contents.htm As
with the Chinese calendar, descriptive information is associated with each
sign, and you can optionally include some of those comments as well, for
extra credit.
- Validating
Input: Your program should validate the date(s) entered before performing
any computation(s).
Extra Credit
Do two or more
of the green choices above.
Notes for both
exercises
- As demonstrated
in class, design your program in a modular fashion, using object-oriented
design techniques, implementing each step incrementally as you go.
- Start early,
NOW!
- Make sure you
enter your name in the NAME at the top
of each file of your java program.
- Once you are
done with the exercise, hand in a
printed (stapled) report that contains the following:
- A printout
of your Java program
- A screen
snapshot of your application.
- A short
essay on your experience in doing this assignment. We want to know
how it all worked out for you and how you feel about completing this
assignment.
- Start NOW!
This cannot be emphasized enough...
Also: Stop by Deepak's Office (no later than April 27 at
2:00p) to show him a demo of your program. Note that the deadline for the Demo
is AFTER the date the project is due. All printed work should still be handed
in by the due date.
There is no credit for late work.
Back to CS110 Spring 2006 Materials.