Homework Assignment #15 (File Input/Output)

Note that the rules for submitting this assignment are slightly different! You'll be submitting your assignments via OnCourse now, instead of by e-mail. Also, many of you forgot to set the permissions properly last time, so don't forget!

For this assignment, you will create two programs called Duplicator.java and Replacer.java.

The Duplicator program will ask the user to input a string to be duplicated. Then it will ask the user how many times it should be duplicated. (If the user enters in something other than a non-negative integer, your program should complain and ask the user to enter the number again.) Then Duplicator will create a new file named originalstring.txt, where originalstring is the string that the user entered. Then, Duplicator will write the originalstring to the new file however many times the user asked for. Lastly, Duplicator will close the file.

The Replacer program will ask for the name of an input file and the name of an output file. If there's a problem opening the input file or the output file, your program should say so and ask the user to try a different filename. Then Replacer should ask for a target string and a replacement string. Next, Replacer should read the contents of the input file, replace every occurrence of the target string with the replacement string, and write the result to the output file.

When you've completed the assignment, make sure that the files containing the source code have read permissions set for everyone, and that the compiled classes file have read and execute permissions set for everyone. Then log on to OnCourse, and go to the Assignments tab and submit your assignment there. Remember to include the paths and the filenames for the source code and the compiled files with your submission!

This assignment is due Tuesday, July 22nd before class.