Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 2

import java.util.*; import java.io.*; import java.util.

Scanner; /**import * The Driver class reads an input file, sends the infromation the to Converter class, and writes an output file. * * @author Henry DeJong * @version 3.6.2014 - ITCS1213-L12 */ public class Driver { // instance variables - replace the example below with your own

/** * Constructor for objects of class Driver */ public static void Main(String []args) throws IOException { char readNextLine; //variable for user input for reading next line StringBuilder sentence; //variable for the sentence being sent in Scanner inputFile; PrintWriter outputFile = new PrintWriter("outSentence.txt"); //declaring the file being outputted inputFile = new Scanner(new File("inputFile.txt")); //IMPORTANT name of file I put in folder for the input, //CHANGE FILE NAME ABOVE IF YOU ARE USING A DIFFERENT NAMED FILE Scanner input = new Scanner(System.in); //declaring keboard input Converter cv = new Converter(); //creating instance of the converter class

System.out.println("This program will read data from a file named inputFile.txt."); //user directions System.out.println("The program will then convert the data line by line and write it"); System.out.println("into a new file named outSentence.txt"); while(inputFile.hasNext()) //loop that runs until there are no lines left { System.out.println(""); //formatting

System.out.println("Press 'y' to read the next line "); readNextLine=input.next().charAt(0); //taking user input if(readNextLine=='y') {

sentence= new StringBuilder(inputFile.nextLine()); //changing the sentence variable to a line from the input System.out.println(" "); System.out.println("Input Record: "); System.out.println("\t"+ sentence);; cv.Converter(sentence); //sends the sentence to the converter class

cv.calcNewString(); //runs the calcNewString method cv.setString(); //runs the setString method

System.out.println("Output Record: " + cv.getConverted()); //prints the new lie System.out.println("\t" + cv.getConverted()); outputFile.println(cv.getConverted()); //saves the new line to an outputted file }

} System.out.println("That's it. Thank you."); inputFile.close( ); //closes files outputFile.close();

} }

You might also like