Watching the Clock
The next project gives you another look at each of the conditional tests you can use in your programs. For this project, you use Java’s built-in timekeeping feature, which keeps track of the current date and time, and present this information in sentence form.
Run NetBeans (or another program to create Java programs) and give a new class the name Clock
. This program is long, but most of it consists of long conditional statements. Type the full text of Listing 7.3 into the source code editor, and save the file.
1: import java.util.*; 2: 3: class Clock { 4: public static void main(String[] arguments) { 5: // get current time and date 6: Calendar now = Calendar.getInstance(); ...
Get Sams Teach Yourself Java™ in 24 Hours, Sixth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.