The setup
Start by creating a project that contains the following class. You should be able to determine the appropriate class and package names from the first few lines of the file.
package edu.unca.cs.csci202;
import java.util.* ;
import java.io.* ;
public class PracticalFall2013 {
public static void main(String[] args) {
// CHANGE 1
// Create a Scanner object from System.in
// Store the Scanner in a variable stdIn
// ... stdIn = ... ;
// CHANGE 2
// Read and trim a line of input using stdIn
// Store the trimmed line in a variable outFilename
// ... outFilename = .... ;
// CHANGE 3
// Using outFilename as a filename, create a PrintWriter
// Store the PrintWriter in a variable outWriter.
// If an exception occurs, simply return from this method.
// ... outWriter = .... ;
// CHANGE 4
// Write a line saying "I'm done" to outWriter
// CHANGE 5
// Do that one final thing that must be done when writing a file.
}
}
The task
Within the Java class there are comments, repeated below, giving four small changes to be made to the program.
- Create an
Scannerobject calledstandardInfrom theSystem.inInputStream. -
Read and trim a line of input using
stdIn. Store the trimmed line inoutFilename. -
Create a
PrintWritercalledoutWriterusing the filename stored inoutFilename. -
If the open succeeded, write a line containing
"I'm done"tooutWriter. - Do that one last thing that needs to be done.
The upload
When you are done, upload your Java program to the IDE Practical dropoff on moodle.