-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharFreq.java
More file actions
42 lines (35 loc) · 929 Bytes
/
CharFreq.java
File metadata and controls
42 lines (35 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
public class CharFreq implements Comparable<CharFreq> {
private char character;
private int frequency;
public CharFreq(char character, int frequency) {
this.character = character;
this.frequency = frequency;
}
public char getChar() {
return character;
}
public int getFreq() {
return frequency;
}
public void setChar(char character) {
this.character = character;
}
public void setFreq(int frequency) {
this.frequency = frequency;
}
public boolean equals(CharFreq other) {
if (character == other.getChar() && frequency == other.getFreq()) {
return true;
}
return false;
}
public int compareTo(CharFreq other) {
if (other.equals(this)) {
return 0;
}
if (other.getFreq() < frequency) {
return 1;
}
return -1;
}
}