// Arup Guha
// 7/20/04
// Edited by Lisa Soros
// 7/9/10
// Sample program for 2004 BHCSI: Frequency Analysis, version 2
// This program allows the user to enter a sentence and then prints out
// a frequency chart for how many times each letter appeared. This chart
// has a star printed for each occurrence of a character.

import java.io.*;
import java.util.*;

public class Freq2 {

  	public static void main(String[] args) throws IOException {

    	Scanner stdin = new Scanner(System.in);

    	// Read in the sentence to analyze.
    	System.out.println("Enter a sentence to analyze.");
    	String text = stdin.nextLine();

    	// Store to lowercase, since case isn't important for this question
    	// and we don't have to retrieve the original case of the sentence.
    	text = text.toLowerCase();

    	// Declare and initialize the frequency array.
    	int[] freq_array = new int[26];
    	int index;

    	for (index=0; index<26; index++)
      		freq_array[index] = 0;

    	// Go through each character in the entered string.
    	for (index=0; index<text.length(); index++) {

      		// Check to see if the current character is a letter.
      		if (isLetter(text.charAt(index))) 

        		// Adjust the appropriate index in the frequency array if necessary.
        		freq_array[text.charAt(index)-'a']++;

    	}

    	printChart(freq_array);

  	}

  	// This method takes in a character and returns true if and only if it
  	// is a lower or upper case letter.
  	public static boolean isLetter(char c) {
    
    	if (c >= 'a' && c <= 'z')
      		return true;
    	else
      		return false;
  	}

  	public static void printChart(int[] freq_array) {

    	int index, index2;

    	// Print out the frequency chart, one line at a time.
    	System.out.println("Letter\tFrequency");
    	for (index=0; index<26; index++) {

      		// Print out the first part of the row.
      		System.out.print((char)('a'+index)+"\t");

      		// Print out one star for each appearance of that letter.
      		for (index2=0; index2<freq_array[index]; index2++)
        		System.out.print("*");

      		System.out.println();
    	}
  	}


}