PROGRAMMING EXERCISES: R D T

advertisement
PROGRAMMING EXERCISES:
READING DATA FROM A TEXT FILE
1. Create a program that reads five (5) names and five (5) numbers from a data file
that you will need to create and name phoneNumbers.txt. The file should
contain a name on one line followed by the person’s phone number on the next
line. The program must then read and output each name and phone number to
a JTextArea when the user clicks OK.
Your program output should look something like this:
Save the project as Phone Numbers in your UNIT 4 folder.
2. Create a program that reads from a comma-delimited data file called
highScores.txt which contains the names of five players and five scores.
Each line within the file should contain a name and a score (commadelimited). The program should be able to read and output each person’s
name and score and calculate the average score, highest score and lowest
score.
When the program launches, the following interface should appear:
Reading Data from a Text File
Page 1 of 3
When the user clicks the OPEN button a JFileChooser object should appear to allow the user to
select a file to read from. Be sure to include a FileNameExtensionFilter object that only lists text
files:
Once a file is selected, the data should be outputted in the JTextArea:
Reading Data from a Text File
Page 2 of 3
If the user clicks the CLEAR button, the data should be cleared from the text field. If the user clicks
the EXIT button, the text area should be cleared.
Save the project as High Scores in your UNIT 4 folder.
Reading Data from a Text File
Page 3 of 3
Download