2016-08-03 17 views
-3

Javaのテキストファイルの上位20語を印刷するプログラムを作ろうとしましたが、3つのクラスがありますが、なぜコンパイルできないのか分かりませんお願い助けて。私はアイデアを持っているあなたに、ツリーのクラスを示しています。なぜ私のプログラムは.txtファイルを認識しないのですか

1) パブリッククラスクライアント{

public static void main(String[] args) { 
    Map<String, Integer> frequencies = new TreeMap<String, Integer>(); 

    while(file.hasNext()){//Este lazo lee las palabras y crea el TreeMap 
     String word= clean(doc.next()); 
     Integer count = frequencies.get(word); 
     if(count==null){ 
      count = 1;} 
     else { 
      count = count + 1; 
     } 
    } 
    Object[] Claves = frequencies.keySet().toArray(); 
    Object[] Valores = frequencies.values().toArray(); 
    Par[] par = new Par[frequencies.size()]; 

    for (int i=0;i<frequencies.size();i++){ 
     Par p = new Par(Claves[i].toString(),(int) Valores[i]); 
     par[i]=p; 
    } 
    Arrays.sort(par); 
    showResult(par); 
} 
public static void showResult(Par[] arreglo){ 
    System.out.println("The 20 most frequently words are "); 
    for(int i= 0; i<=19; i++){ 
     System.out.print("Word "+ arreglo[i].Clave + " in " + arreglo[i].Valor + " times."); 
    } 
} 

}パー匹敵{ 文字列クラーベを実装 2) パブリッククラス。 int Valor; public int length;

public Par(String clave, int valor){ 
    this.Clave = clave; 
    this.Valor = valor; 
} 

public int compareTo(Par p) { 
     if(this.Valor<p.Valor){ 
      return 1; 
     } 
     else if(this.Valor==p.Valor){ 
      return 0; 
     } 
     else{ 
      return -1; 
     }   
} 

} 3) パブリッククラスProcessText {

public void reader(Path r){ 
    String name = clean(file.getName()); 
     if(file.getName().equals(name + ".txt" || file.getName().equals(name + ".doc"))){ 
      try (Scanner sc = new Scanner(r)){ 
       String doc = ""; 
       while(sc.hasNextLine()){ 
        String linea = (sc.nextLine()); 
        doc = doc.concat(linea + "\n"); 
       } 
       sc.close(); 
      } 
     } 
} 

public static String clean(String s){ 
    String r = ""; 
    for (int i=0;i<s.length();i++){ 
     char c = s.charAt(i); 
     if (Character.isLetter(c)){ 
     r = r + c; 
     } 
    } 
    return r.toLowerCase(); 
} 

}

+0

todos los votantes。 Sí、yaséqueestáen en ingles。いいえvuelvan a cerrar la pregunta。シラバスはモビボである。 –

+1

なぜそれをコンパイルできないのですか?エラーメッセージとは何ですか? –

+0

この質問を閉じるには投票する – haifzhan

答えて

0

これはあなたが持っているすべてのコードである場合は、あなたの問題はあなたの主なメソッドが呼び出される変数を作成したことがないということかもしれません"doc"または "file"ですが、クライアントのmainメソッドの開始時に両方を使用します。

コンパイル時のエラーを共有することができればもっと役に立ちます。だから、これがあなたの問題であるとは確信できません。

関連する問題