Can I have some help fixing some errors in my JAVA code. 1. public FileChar() {
ID: 3726468 • Letter: C
Question
Can I have some help fixing some errors in my JAVA code.
1. public FileChar() {
ch = ' '; //error invalid character constant
}
2. public int hashCode() {
return ch.hashCode(); //error cannot invoke hashCode on primitive type char
}
3. public int compareTo(FileChar Char) {
return ch.equals(Char.ch); //error cannot invoke equals(Char) on primitive type char
}
4. public int compareTo(HuffElement he) {
return chCount.equals(he.chCount); //error cannot invoke equals(int) on primitive type int
}
5. public String toString() {
return System.out.println("char: " + ch + "code: " + "count: " + code + chCount); //error cannot return a void result
}
Explanation / Answer
1. public FileChar() {
char ch = ' ';
}
2. public int hashCode() {
return new Character(ch).hashCode();
}
3. public int compareTo(FileChar Char) {
return new Character(ch).equals(Char.ch);
}
4. public int compareTo(HuffElement he) {
return new Integer(chCount).equals(he.chCount);
}
5. public String toString() {
return "char: " + ch + "code: " + "count: " + code + chCount;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.