//reads input text file to find most used letter(s), this then written
//to output file

import java.io.*;

public class MostLetters {
	public static void main(String[] args) {

		LetterData store = new LetterData();		//set up new storage object
		
		try {										//reading input file
			FileReader fR;
			BufferedReader bR;
			fR = new FileReader("sample.txt");
			bR = new BufferedReader(fR);
			int inInt;
			inInt = bR.read();
			while (inInt != -1) {
				store.addLetter(inInt);
				inInt = bR.read();
			}
		} catch(IOException e) {
			System.out.println("Error in reading input file");
		}
		
		System.out.println(store.getMaxLetters());	//output to screen
	
	
		try {										//writing results file
			FileOutputStream oS = new FileOutputStream("results.txt");
			PrintWriter pW = new PrintWriter(oS);
			pW.println(store.getMaxLetters());		//output max letters
			pW.println(store.getLetterList());		//output letter list
			try {
				for (char n = 'A'; n <= 'Z'; n++) {
					pW.println();
					pW.print(n);
					pW.print("\t");
					for (int m = 0; m < store.getLetterNumber(n); m++) {
						pW.print("*");
					}
				}
			} catch (Exception e) {}
			pW.flush();
			pW.close();
		} catch (IOException e) {
			System.out.println("Error in writing results file");
		}		
	}
}