Advertisement
panaewboi

320feb28WordCounter

Feb 27th, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1.  
  2. import java.util.Comparator;
  3.  
  4. /*
  5. * To change this license header, choose License Headers in Project Properties.
  6. * To change this template file, choose Tools | Templates
  7. * and open the template in the editor.
  8. */
  9.  
  10. /**
  11. *
  12. * @author INT303
  13. */
  14. public class WordCounter {
  15. private String word;
  16. private int count;
  17.  
  18. public WordCounter(String word) {
  19. this.word = word;
  20. this.count = 1;
  21. }
  22.  
  23. public String getWord() {
  24. return word;
  25. }
  26.  
  27. public int getCount() {
  28. return count;
  29. }
  30.  
  31. public void increment(){
  32. this.count++;
  33. }
  34.  
  35. @Override
  36. public String toString() {
  37. return "WordCounter{" + "word=" + word + ", count=" + count + '}';
  38. }
  39.  
  40.  
  41. public static Comparator<WordCounter> getFreqDescComparator(){
  42. return new Comparator<WordCounter>(){
  43. @Override
  44. public int compare(WordCounter wc1, WordCounter wc2){
  45. return wc2.getCount() - wc1.getCount();
  46. }
  47.  
  48. }
  49. return ; -----------------------------------------------------
  50.  
  51. }
  52.  
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement