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.
Listing 7.3. The Clock Program
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(); ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access