CS 110 Introduction to Computing
Fall 2000
Project #4: Birthday Numerology
Due in class on Tuesday, April 9, 2002
Write a Java applet 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.
- Compute and output their Zodiac sign.
- Compute 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.
Here is an example applet for your guidance. Your applet should have similar
functionality, but design the GUI on your own, this is just a sample design.
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. Another way to do it is to
pre-compute the years between 1900 and 2999 that are prime numbers
(do this separately from your program) and then just test to
see if the year the person typed in is one of those. Either method
(or any other one you happen to know that works) is fine. 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 Chapter 12 of your Lab Manual. 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 2000 is a dragon
year) 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
- In CodeWarrior, use the Java 2 stationery.
- You will not be able to view your applet in Netscape on Macs
due to a shortcoming in Netscape's Java compatibility. However,
all current versions of Internet Explorer (on Macs and PCs),
and netscape (on PCs) will work just fine. For all your CodeWarrior
work continue to use the Applet Viewer.
- Play close attention to the syntax. Every Java instruction
has to be written with proper punctuations as well as with consistent
use of upper/lower case character combinations.
- Make sure you enter your name in the NAME
slot at the top of the program. Also, use the SIGNATURE
slot in your applet.
- Once you are done with the exercise, post your applet on your web page and
hand in a printed (stapled) report that contains the following:
- A printout of your Java program
- A screen snapshot of your applet.
- A printout of your project window. To do this, simply click
the mouse in the project window and then chose print from the
File menu.
- 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.
Back to: CS110 Course Materials