Java Reference
In-Depth Information
m.
Make a copy of another date. Given a reference to an object containing a
date, copy the data members of the object into the corresponding data
members of this object.
n.
Write the definitions of the methods to implement the operations defined
for the
class
Date
.
8.
The
class
Date
defined in Programming Exercise 7 prints the date in
numerical form. Some applications might require the date to be printed in
another form, such as March 24, 2015. Derive the
class
ExtDate
so that
the date can be printed in either form.
Add a data member to the
class
ExtDate
so that the month can also be
stored in string form. Add a method to output the month in the string format
followed by the year—for example, in the form March 2015.
Write the definitions of the methods to implement the operations for the
class
ExtDate
.
9.
Using the
class
es
ExtDate
(Programming Exercise 8) and
Day
(Chapter 8,
Programming Exercise 3), design the
class
Calendar
so that, given the month
and the year, we can print the calendar for that month. To print a monthly
calendar, you must know the first day of the month and the number of days in that
month. Thus, you must store the first day of the month, which is of the form
Day
,
and the month and the year of the calendar. Clearly, the month and the year can be
stored in an object of the form
ExtDate
by setting the day component of the date
to
1
, and the month and year as specified by the user. Thus, the
class
Calendar
has two data members: an object of type
Day
and an object of type
ExtDate
.
Design the
class
Calendar
so that the program can print a calendar for any
month starting January 1, 1500. Note that the day for January 1 of the year 1500
was a Monday. To calculate the first day of a month, you can add the appropriate
number of days to Monday, January 1, 1500.
For the
class
Calendar
, include the following operations:
a.
Determine the first day of the month for which the calendar will be
printed. Call this operation
firstDayOfMonth
.
b.
Set the month.
c.
Set the year.
d.
Return the month.
e.
Return the year.
f.
Print the calendar for the particular month.
g.
Add the appropriate constructors to initialize the data members.
10. a.
Write the definitions of the methods of the
class
Calendar
(designed
in Programming Exercise 9) to implement the operations of the
class
Calendar
.
b.
Write a test program to print the calendar for either a particular month
or a particular year. For example, the calendar for September 2014 is:
1
0
Search WWH ::
Custom Search