Java

TOPIC I02 – WRITING TO A FILE

 

LESSON WORK

 

 

QUESTION #1

 

Create a program that will create a file named “even.txt”.  It will output all even numbers from 0 to 1000 in the file.

 

QUESTION #2 (SMALL PROJECT)

 

a) Save the following file to your work folder: dictionary.txt.

 

b) You will now write the program that will get a word from the user and state whether the word is in the dictionary or not.  This should occur within a loop so that the user can check many words.

 

c) Make the following addition to your program from b:

 

If the word is not in the dictionary, you must offer to add the word to the dictionary.  If the user wants it added, you must do so.  However, to conserve the integrity of the dictionary, you must add the word to a second dictionary called dictionary2.txt. 

 

Remember that you now need to check two files to see if a word is in the dictionary.

 

d) Add the following option:

 

If the user enters the word “\clear”, the second dictionary is erased.  You should include a “Are you sure you want to clear the second dictionary?” message.