InClassExercise14

InClassExercise14 - method, transferNegativeNumbers(String...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
CS112: In-class Exercise 14 Writing to a file 1. Create a new project files-14 . 2. Create a new class, called Testing . Delete everything but the outer wrapper. 3. In this Testing class, create the following method. There are no instance variables for this class. We are just going to write and test methods. Use local variables where needed. Remember to import appropriate classes before the outer wrapper so that we have to ability to read and write files. Write a void method, writeNumbersToFile(String filename, int n) throws Exception that will write the numbers 1 through n to the file filename . Each number should be on its own line. Note that you have to create this file if it doesn’t already exist. You will need to use a loop. Create a Testing object, and invoke the writeNumbersToFile method with input String “out1.txt” and integer 20. And then again with “out2.txt” and integer 55. 4. ( HW#7) In this Testing class, create the following method. Write a void
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: method, transferNegativeNumbers(String infilename, String outfilename) throws Exception that will open and read all the numbers from the input file filename . As the numbers are being read, this method will save all the negative numbers to the output file outfilename . Note that you have to create this file if it doesnt already exist. You will need to use a loop and an if statement, of course. Think about the order that you will need to execute these commands. Create a Testing object, and invoke the transferNegativeNumbers method with input Strings input1.txt and output1.txt. And then again with input2.txt and output2.txt. Get the input files from the usual downloads locations. Remember that the input file should be in the project folder. For reference, the online java documentation that describes constructors and methods for built-in classes and libraries is http://java.sun.com/javase/6/docs/api/...
View Full Document

This lab report was uploaded on 04/08/2008 for the course CSCI 112 taught by Professor Yuen during the Fall '07 term at Lake Forest.

Ask a homework question - tutors are online