19.09.2015 Views

Prentice.Hall.Introduction.to.Java.Programming,.Brief.Version.9th.(2014).[sharethefiles.com]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

592 Chapter 15 Abstract Classes and Interfaces<br />

*15.3 (Shuffle ArrayList) Write the following method that shuffles an ArrayList of<br />

numbers:<br />

public static void shuffle(ArrayList list)<br />

*15.4 (Sort ArrayList) Write the following method that sorts an ArrayList of numbers.<br />

public static void sort(ArrayList list)<br />

**15.5 (Display a calendar) Write a program that displays the calendar for the current<br />

month, as shown in Figure 15.10. Use labels, and set text on the labels <strong>to</strong> display<br />

the calendar. Use the GregorianCalendar class <strong>to</strong> obtain the information for<br />

the month, year, first day of the month, and number of days in the month.<br />

JLabel<br />

JPanel with<br />

GridLayout<br />

Each cell is<br />

a JLabel<br />

FIGURE 15.10<br />

The program displays the calendar for the current month.<br />

**15.6 (Display calendars) Rewrite the PrintCalendar class in Listing 5.12 <strong>to</strong> display<br />

a calendar for a specified month using the Calendar and<br />

GregorianCalendar classes. Your program receives the month and year<br />

from the <strong>com</strong>mand line. For example:<br />

java Exercise15_06 1 2012<br />

This displays the calendar shown in Figure 15.11.<br />

FIGURE 15.11 The program displays a calendar for January 2012.<br />

You also can run the program without the year. In this case, the year is the current<br />

year. If you run the program without specifying a month and a year, the<br />

month is the current month.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!