Free University of Bolzano/Bozen
Faculty of Computer Science - Bachelor in Applied Computer Science
Bachelor in Production Engineering
Introduction to Programming - A.A. 2004/2005
Exercise
Class Date
Part 1: Design and realize a Java class
Date
to represent dates. The following functionalities are of
interest for dates:
- creation of a date from three integers, representing respectively the
day, the month, and the year;
- return of the day of the date;
- return of the month of the date;
- return of the year of the date;
- test if two dates are equal;
- test if one date precedes another one.
Add to the class also a method that does overriding of toString
inherited from Object
in such a way that it returns a string
representing a date in a suitable way.
Part 2: Write a static method, external to the class
Date
that, given a Date
as a parameter, returns the
date of the following day.
Part 3: Write a client that makes use of the class
Date
as follows:
- It creates two dates, by reading day, month, and year from the keyboard,
and prints them.
- It calculates the date of the day following the second date, and prints
it.
- It prints a suitable messagge depending on whether the two dates are
equal, the first one precedes the second one, or the second one precedes
the first one.