-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharAndFreq.java
More file actions
50 lines (48 loc) · 954 Bytes
/
CharAndFreq.java
File metadata and controls
50 lines (48 loc) · 954 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
43
44
45
46
47
48
49
50
/**
* Class which stores a character and a frequency.
* @author Jasper Bingham
*/
public class CharAndFreq
{
private char myChar;
private int myFreq;
/**
* Constructor.
* @param thisChar the character
* @param freq the letter's frequency
*/
public CharAndFreq(char thisChar, int freq)
{
myChar = thisChar;
myFreq = freq;
}
/**
* Returns the character.
* @return the character
*/
public char getChar()
{
return myChar;
}
/**
* Returns the frequency of the character.
* @return the frequency of the character
*/
public int getFreq()
{
return myFreq;
}
/**
* Prints out CharAndFreq's that have non-empty characters in the format character -> frequency
* @return the String representation of a CharAndFreq with a non-empty character
*/
public String toString()
{
//if character is empty, only print frequency
if(myChar == '\0')
{
return "" + myFreq;
}
return myChar + "->" + myFreq;
}
}