Java Reference
In-Depth Information
4.1 Using a text editor or wordprocessor, create a text fi le holding a series of sur-
names and payroll numbers (at least fi ve of each). For example:
Now write a Java program that uses a while loop to read values from the above
text fi le and displays then in a table under the headings 'Surname' and 'Payroll
No.'. (Don't be too concerned about precise alignment of the columns.)
4.2 Take a copy of the above program, rename the class and modify the appropriate
line so that the program accepts input from the standard input stream (i.e., using
a Scanner around the standard input stream, ). Then use redirection to
feed the values from your payroll text fi le into your program (displaying the
contents as before).
4.3 Write a (very short) program that creates a serial text fi le holding just two or
three names of your own choosing. After compiling and running the program,
use the MS-DOS command type (or the equivalent command for your plat-
form) to display the fi le's contents. For example:
type names.txt
4.4 Using a text editor or word processor, create a text fi le containing a series of fi ve
surnames and examination marks, each item on a separate line. For example:
By extending the code given below, create a random access fi le called results.
dat , accepting input from the standard input stream (via a Scanner object) and
redirecting input from the above text fi le. Each record should comprise a student
surname and examination mark. When all records have been written, reposition
the fi le pointer to the start of the fi le and then read each record in turn, displaying
its contents on the screen.
Search WWH ::

Custom Search