Java Reference
In-Depth Information
*15.3
(
Shuffle ArrayList
) Write the following method that shuffles an
ArrayList
of
numbers:
public static void
shuffle(ArrayList<Number> list)
*15.4
(
Sort ArrayList
) Write the following method that sorts an
ArrayList
of numbers.
public static void
sort(ArrayList<Number> list)
**15.5
(
Display a calendar
) Write a program that displays the calendar for the current
month, as shown in Figure 15.10. Use labels, and set text on the labels to display
the calendar. Use the
GregorianCalendar
class to obtain the information for
the month, year, first day of the month, and number of days in the month.
JLabel
JPanel
with
GridLayout
Each cell is
a
JLabel
F
IGURE
15.10
The program displays the calendar for the current month.
**15.6
(
Display calendars
) Rewrite the
PrintCalendar
class in Listing 5.12 to dis-
play a calendar for a specified month using the
Calendar
and
GregorianCalendar
classes. Your program receives the month and year
from the command line. For example:
java Exercise15_06 1 2012
This displays the calendar shown in Figure 15.11.
F
IGURE
15.11
The program displays a calendar for January 2012.
You also can run the program without the year. In this case, the year is the cur-
rent year. If you run the program without specifying a month and a year, the
month is the current month.