Sams Teach Yourself Java™ in 24 Hours (Covering Java 7 and Android)

(singke) #1
ptg7068951

Watching the Clock 89

52: break;
53: case6:
54: System.out.print(“June”);
55: break;
56: case7:
57: System.out.print(“July”);
58: break;
59: case8:
60: System.out.print(“August”);
61: break;
62: case9:
63: System.out.print(“September”);
64: break;
65: case10:
66: System.out.print(“October”);
67: break;
68: case11:
69: System.out.print(“November”);
70: break;
71: case12:
72: System.out.print(“December”);
73: }
74:
75: // display the date and year
76: System.out.println(“ “ + day + “, “+ year + “.”);
77: }
78: }


After the program compiles correctly, look it over to get a good idea about
how the conditional tests are being used.


With the exception of Line 1 and Lines 6–11, the Clockprogram contains
material that has been covered up to this point. After a series of variables
are set up to hold the current date and time, a series of ifor switchcondi-
tionals are used to determine what information should be displayed.


This program contains several uses of System.out.println()and
System.out.print()to display strings.


Lines 6–11 refer to a Calendarvariable called now. The Calendarvariable
type is capitalized because Calendaris an object.


You learn how to create and work with objects during Hour 10, “Creating
Your First Object.” For this hour, focus on what’s taking place in those
lines rather than how it’s happening.


LISTING 7.3 Continued

Free download pdf