$20.00 Program composition
Write a Date Class to add to the program you wrote last week (The Student Class
Program) One basic rule of OO programming is not to save anything that can be calculated.
The date class will allow you to calculate the student’s age.
A date class
§ Set and
get each attribute
§ Calculates age in a behavior
called calcage( ) that determines a person’s age as of today
each attribute – as part of the set method call the validate methods
1 to the number of days in the month
Don’t forget leap year. Leap year is more than every 4th year is a leap year – look it
Accept 3-letter abbreviations; Jan, Feb, Mar, . . .
Make the input case insensitive. Also accept integers, 1 – 12
Is 99 a valid year? Is 10 a valid year?
If 99 means 1999 does 10 mean 1910?
Define a year format and enforce it.
Add birth date as an attribute to your Student – an abstract variable (one created
from an abstract data type) that is an attribute of another abstract data type
(such as your Student Class) illustrates Composition.
Add methods to your StudentManip class to input (set) the student’s birth date and
to calculate the student’s age. Add the student’s age to the display classes.
- This tutorial hasn't been purchased yet.
- Posted on May. 22, 2012 at 12:18:38AM