Import java.util.Scanner;
class Dict
{ private class Pair
{ public String word;
public int count;
public Pair(String w, int c)
{ word = w;
count = c;
}
public String getWord()
{ return word;}
public void setWord(String newword)
{ word = newword; }
public String toString()
{ return word + " " + count; }
}
private Pair[] p;
private int psize;
public Dict()
{ p = new Pair[1];
psize = 0;
}
public void insert(Pair x)
{ if (psize == p.length)
{ Pair[] pp = new Pair[psize*2];
System.arraycopy(p, 0 , pp, 0 ,psize);
p = pp;
}
for ( int i = 0; i<psize; i++)
if ( p.getWord().equals(x.getWord()))
{ p.setWord(x.getWord());
return;
}
p[psize++] = x;
psize++;
}
public Pair find(Pair x)
{ for ( int i = 0; i<psize; i++)
if ( p.getWord().equals(x.getWord()))
return p;
return null;
}
public String toString()
{ String s="";
for (int i = 0; i<psize; i++)
{ s += p.toString() + '\n';
}
return s;
}
}
public class MainDict
{ public static void main(String[] args)
{ Scanner c = new Scanner(System.in);
String text = "";
while (c.hasNextLine())
text += c.nextLine() + '\n';
Dict dict = new Dict();
String word = "";
for ( int i = 0; i<text.length(); i++)
{ char l = text.charAt(i);
if (Character.isLetter(l))
word += l;
if (word.length()>0)
{ Pair x = new Pair(word, 1);
Pair p = dict.find(x);
if ( p != null)
p.count++;
else
dict.insert(x);
word = "";
}
}
System.out.println(dict);
}
}
ma in compilazione mi dà questo errore
MainDict.java:69 find(Dict.pair) cannot be applied to (Pair)
Pair p = dict.find(x);
MainDict.java:73 insert(Dict.pair) cannot be applied to (Pair)
dict.insert(x);
Sarò stanca, non lo so, ma non riesco a capire il perchè..
Grazie