Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote