title: - Character Counter - Array
body: <p>Design a program that reads an ASCII text file (provided) one byte at a time and produces an
  output file that contains the frequency count of how many times each character appears in the
  input file. Do not sort the output. A character frequency class instance must be used to
  represent each unique character in the file (see below). For this exercise, the character
  frequency objects must be processed and stored using an array.</p>
  
  <p>I have tried creating an object of Character Frequencies and using an equals method to compare it with input.</p>
  
  <p>The array is supposed to be storing new characters and frequency of characters but it is also storing duplicates and frequency is not accurate. </p>
  
  <pre><code>public class CharacterFrequency {
  //Stores character by character from input file to check if its in ASCII 
  array
  private static char character;
  //Stores number of times character shows up in input file
  private static int frequency = 0;
  private static CharacterFrequency arr[] = new CharacterFrequency[256];
  //Constructor class for CharacterFrequency
  public CharacterFrequency(char character, int frequency){
      setCharacter(character);
      setFrequency(frequency);
  }
  
  public static void main(String[] args){
      //initiate object array to store character and frequency variables
  
          File file = new File("C:/Users/alber/Desktop/sample.txt");
          if (!file.exists()) {
            System.out.println(args[0] + " does not exist.");
            return;
          }
          if (!(file.isFile() &amp;&amp; file.canRead())) {
            System.out.println(file.getName() + " cannot be read from.");
            return;
          }
          try {       
  
              FileReader fr = new FileReader("C://Users/alber/Desktop/sample.txt");               
  
                      //loop through character array 
  
                      for(int i = 0; i &lt; arr.length; i++){
                      //read file character by character until no characters 
    are left and store character each time 
  
                      int j = 0;
                      while ((j=fr.read()) != -1){
  
                          character = (char)j;
                          //if character is in the array already do not add 
   it just call increment method                                      
                          //if(arr[i].equals(character)){ 
                          if(arr[i] == null || (! 
  (arr[i].equals(character)))){
                              arr[i] = new 
    CharacterFrequency(character,frequency);
                              System.out.println(arr[i]);
                          //if character is not in the array add it to it  
                          }else{                                  
                              increment();    
  
  
                          }//end else   
  
                      }//end while
  
                      }//end for
  
               fr.close();                 
          } catch (IOException e) {
            e.printStackTrace();
          }
  
      }
  public char getCharacter(){
      return character;
  }
  
  public static void setCharacter(char character){
  
  }
  
  public int getFrequency(){
      return frequency;
  }
  
  public void setFrequency(int frequency){
      this.frequency = frequency;
  }
  
  public static void increment(){
      frequency++;
  }
  @Override
  public boolean equals(Object obj){
  
      if(obj == null || obj.getClass()!= this.getClass()){
      return false;
      }
      if(obj == this){
      return true;
      }
  
      CharacterFrequency c = (CharacterFrequency)obj;
      return CharacterFrequency.character == this.character &amp;&amp; CharacterFrequency.frequency == this.frequency;
  }
  
  public String toString(){
  
      return character + " " + frequency;
  }
  
  }
  </code></pre>