import java.io.*;
import java.util.Arrays;
import java.util.Scanner;

/******************************************************
 * @author Nancy Harris
 * @version 2-2/2014 - This version asks the user for file names 
 ******************************************************/

public class FileIO
{
	/*************************************************
	 * @param args unused in this application
	 *************************************************/
	public static void main(String[] args) 
	{
		// declarations for the IO part. Note the imports.
		Scanner keyboard;
		Scanner fileScan = null;
		PrintWriter fileWriter = null;
		String inText;
		String [] outText;
		
		keyboard = new Scanner(System.in);
		fileScan = getInputScanner(keyboard);
		fileWriter = getOutputWriter(keyboard);
		keyboard.close();
		
		inText = readText(fileScan);
		fileScan.close();
				
		outText = processText(inText);

		writeText(fileWriter, outText);
		
		// 7. close your Scanners and PrintWriter.
	}
		

	/*************************************************
	 * the getInputScanner will instantiate the File object
	 * and then build open the file using 
	 * a file Scanner. If the file cannot be opened, print a message 
	 * to the user, "Missing file: " followed by the name of the file.
	 * Use the File class's getName method for the name.
	 * 
	 * @param keyboard The keyboard Scanner to use (V2)
	 * @return A file Scanner to read the selected file.
	 *************************************************/
	private static Scanner getInputScanner(Scanner keyboard)
	{
		Scanner fileScan = null;
		File inFile;
		String inFileName;

		// a. Instantiate the File object
			
		
		// b. Open fileScan for reading
		
		
		return fileScan;
	}

	/*************************************************
	 * Instantiate the File object using the file name provided.
	 * Then instantiate the PrintWriter in a try block. If the file
	 * cannot be opened, the method shold print the specified error 
	 * message.
	 * 
	 * @param keyboard The keyboard Scanner to use (V2)
	 * @return A file PrintWriter to read the selected file.
	 *************************************************/
	private static PrintWriter getOutputWriter(Scanner keyboard)
	{
		PrintWriter fileWriter = null;
		File outFile;
		String outFileName;

		// a. Instantiate the File object
		
		// b. Open the PrintWriter for writing
		
		return fileWriter;
	}


	/*************************************************
	 * Using the Scanner parameter, read the lines from the 
	 * file to build a single String of text. Be sure to add the 
	 * \n character after each file read.
	 * 
	 * @param fileScan The input file Scanner
	 * @return A String representing all of the text in the file.
	 *************************************************/
	private static String readText(Scanner fileScan)
	{
		String inText = "";

		// a. Read the test from the file, storing it in inText
		
		return inText;
	}

	/*************************************************
	 * processText creates a TextAnalyzer object and then generates
	 * some data about the text contained in the analyzer. 
	 * 
	 * @param inText The text to analyze
	 * @return A String array containing three lines describing
	 *         the text.
	 *************************************************/
	private static String[] processText(String inText)
	{
		TextAnalyzer theAnalyzer = new TextAnalyzer(inText);
		String[] outText = new String[3];

		outText[0] = String.format("This file has %d words and %d characters",
				theAnalyzer.countWords(), theAnalyzer.getLength());
		outText[1] = String.format("'s' appears %d times.", 
				theAnalyzer.countLetters('s'));
		outText[2] = String.format("All letters: %s.", 
				Arrays.toString(theAnalyzer.countLetters()));
		return outText;
	}

	/*************************************************
	 * writeText writes the contents of the String[] parameter to the
	 * PrintWriter
	 * 
	 * @param fileWriter The PrintWriter to output to
	 * @param outText The text to output
	 *************************************************/
	private static void writeText(PrintWriter fileWriter, String[] outText)
	{
		// a. output the data found in outText
		
	}
		
}
