//class for text processing

public class LetterData {
	private int[] data;

	public LetterData() {					//constructor
		data = new int[26];
		for (int n = 0; n <= 25; n++) data[n] = 0;
	}

	public void addLetter(int letter) {		//add letter instance
		if ((letter >= 'A') && (letter <= 'Z')) data[letter - 'A']++;
		if ((letter >= 'a') && (letter <= 'z')) data[letter - 'a']++;
	}

	public int getMaxNo() {					//get maximum number
		int max = 0;
		for (int n = 0; n <= 25; n++) {
			if (data[n] > max) max = data[n];
		}
		return max;
	}

	public String getMaxLetters() {			//get letters at maximum
		int max_count;
		String outString = "";
		int max = getMaxNo();
		if (max != 0) {
			max_count = 0;
			for (int n = 0; n <= 25; n++) {
				if (data[n] == max) {
					outString += ((char)(n + 'A')) + " ";
					max_count++;
				}
			}
			if (max_count > 1) outString += "are the most used letters";
			else outString += "is the most used letter";
		} else outString += "The file contained no letters";
		return outString;
	}
	
	public String getLetterList() {			//get list of all letters used
		String outString = "All letters used: ";
		boolean none = true;
		for (int n = 0; n <= 25; n++) {
			if (data[n] > 0) {
				outString += ((char)('A' + n)) + " ";
				none = false;
			}
		}
		if (none) outString += "none";
		return outString;
	}
	
	public int getLetterNumber(char ch) throws Exception {
		int index = -1;
		if ((ch >= 'A') && (ch <= 'Z')) index = ch - 'A';	//uppercase
		if ((ch >= 'a') && (ch <= 'z')) index = ch - 'a';	//lowercase
		if (index < 0) throw new Exception();
		return data[index];
	}
	
}