import java.text.DecimalFormat;

class TextdateiAuf_E_untersuchen
{   // Bezugsobjekte
    SimpleInput in;      // Das Objekt der Klasse SimpleInput deklarieren.

    // Attribute
    int e_Anzahl, gesamtAnzahl;
    double prozentsatz;
    
    // Konstruktor
    public TextdateiAuf_E_untersuchen()
    { in = new SimpleInput(); // Das Objekt der Klasse SimpleInput erzeugen. 
      e_Anzahl = 0;
      gesamtAnzahl = 0;
    }
    
    // Dienste
    public String prozentsatz_mit_2_Nachkommastellen(double x)
    { java.text.DecimalFormat d = new java.text.DecimalFormat("0.00%");
      return d.format(x).toString();
    }
    
    public void weiterzaehlen(char c)
    { if (Character.isLetter(c)) 
          { gesamtAnzahl++;
            if (c == 'e' || c == 'E') e_Anzahl++;
          }  
    }

    public void statistikAusgeben()
    { prozentsatz = 1.0 * e_Anzahl/gesamtAnzahl;
      String prozent = prozentsatz_mit_2_Nachkommastellen(prozentsatz);  
      Out.println("Es wurde " + e_Anzahl + " mal der Buchstabe E gefunden.");
      Out.println("Das sind " + prozent + ".");
    }  
    
    public void dateiAnalysieren(String dateiname)
    { char ch;
      boolean okay;
      In.open(dateiname); 
      if (In.done())
           {  do
              {  ch = In.read();
                 okay = In.done() || (ch==In.eof);
                 if (okay && ch!=In.eof) weiterzaehlen(ch);
              } while ((ch!=In.eof) && okay);
              if (!okay) Out.println("Lesefehler!");
              In.close();
           }
      else {  Out.println("Die Datei " + dateiname + " existiert nicht."); }
    } // dateiAnalysieren
    
    public void nun_mach_mal_was()
    { String name = in.getString("Name der Datei, die analysiert werden soll? ");
      if (name.length() == 0) Out.println("Kein Dateiname angegeben!");
      else { dateiAnalysieren(name);
              statistikAusgeben();
           }
    } // nun_mach_mal_was
} // class Textdatei
