Starting from:

$30

Lab 6 Solution

Goal:

Practice input and output text file

Read in data from input files

Write data to output files

Check file exists or not

 

Task: Write a complete Java program that opens two input files one named “roster.txt”, the other named “scores.txt”. For any of these two files, if a file doesn’t exist, exit the program with an error message, otherwise, open the file. Ask the user enter an output file name for the keyboard. If the output file exists, display a message that the old content will be wiped out. Read in names line by line from the first input file, convert names to all uppercase letters and write to the output file with names separated by a space. Then, read in scores one by one, add 5 points to each score and write scores to output file separated by a space. When finish, close all three files.




(Hint: your output will contain two lines, first name is a list of names separated by a space and the second line is a list of scores separated by a space.)




Both input files roster.txt and scores.txt are attached. Create a script file containing a copy of your program code, and the test run.




 

Submission: Submit your Java program source code (i.e. .java file), the script file, and the output file to blackboard along the Lab6 link.



More products