Java Reference
In-Depth Information
The println() method of the System.out object causes each output String to
display on a new line in the command prompt window. The System.out object
supports other output methods in addition to the println() method. For exam-
ple, the System.out object supports the print() method, which prints output on a
single line, without moving the insertion point down to the next line. The
print() method is useful when you want the insertion point to display directly
after a prompt to the user. You can use the Java API and language documenta-
tion on the Sun Microsystems Web site to research other methods supported by
the System.out object.
Editing the Source Code
When you edit or modify the source code in any way, you must repeat the steps
of saving, compiling, and executing the program. Even if you make a simple
change, such as editing the spacing between characters, you should repeat the
steps of saving, compiling, and executing the program to ensure that the pro-
gram runs properly.
The source code of the Welcome to My Day application must be edited so
that the application obtains the current date from the operating system, displays
the date, and formats the output as requested in the requirements document.
Figure 2-33 shows the source code after the edits are complete.
1
/*
2
Chapter 2:
Welcome to My Day
3
Programmer: J. Starks
4
Date:
October 4, 2007
5
Filename:
Welcome.java
6
Purpose:
This project displays a welcome message, the user's
7
name, and the system date in a console application.
8
*/
9
10
import java.util. Date ;
11
12
public class Welcome
13
{
14
public static void main ( String [] args )
15
{
16
Date currentDate = new Date () ; // Date constructor
17
System .out.println () ;
18
System .out.println ( "\t\t\tWelcome to my day!" ) ;
19
System .out.println ( "\t\t\tDaily planner for Linda Nunez" ) ;
20
System .out.println ( "\t\t\t" + currentDate ) ;
21
System .out.println () ;
22
}
23
}
FIGURE 2-33
TextPad allows programmers to use standard editing techniques, such as
those used in a word processing program, to replace and enter new code in the
coding window. The Edit menu in the TextPad menu bar displays commands for
Search WWH ::




Custom Search