CSCI-1320 Homework 15: File Writing

Instructor: Todd Dole

Purpose Statement

This assignment gives practice writing a file.

Instructions

This assignment will be similar to homework 10, where we generated a series of random numbers. But this time, we will save the numbers to a file.

Prompt the user for the name of a file to create, and the number of random numbers to generate.

Then, generate the specified number of random numbers, using Math.random()*1000.0

Write each number to the file specified, with one number per line.

Be sure to close the file when finished, and print a message letting the user know the file has been created.

Include a try/catch block to catch any errors and display an appropriate message.

Example input:

                Please enter the name of the file you want to create: numbers.txt
                How many random numbers do you want? 100
                File numbers.txt created

            
This example would create a file called numbers.txt containing 100 random numbers.