public class Candidate implements Comparable<Candidate> {
  public int compareTo(Candidate other) {
    return 0; 
  }
  public Candidate(String name, int votes) {
    this.name = name;
    this.votes = votes;
  }
  private String name;
  private int votes; 
  public String toString() {
    return this.name + ":" + this.votes; 
  }
}

--

import java.io.File; 
import java.util.Scanner; 
import java.util.Map; 
import java.util.HashMap; 
import java.util.ArrayList;
import java.util.Collections;

public class Election {
  public static void main(String[] args) throws Exception {
    String fileName = args[0]; 
    File file = new File(fileName); 
    Scanner read = new Scanner(file); 
    Map<String, Integer> m = new HashMap<String, Integer>(); 
    // https://docs.oracle.com/javase/8/docs/api/java/util/Scanner.html#Scanner-java.io.File-
    while (read.hasNext()) {
      String word = read.next(); 
      // System.out.println( word ); 
      if (m.get(word) == null) {
        m.put(word, 1);  
      } else { 
        m.put(word, 1 + m.get(word)); 
      }
    }
    System.out.println( m ); 
    ArrayList<Candidate> a = new ArrayList<Candidate>(); 
    // https://docs.oracle.com/javase/8/docs/api/java/util/Map.html#keySet--
    for (String key : m.keySet()) {
      System.out.println( key + ": " + m.get(key) );  
      a.add(new Candidate( key , m.get(key) )); 
    }
    System.out.println(a); 
    Collections.sort(a); 
    System.out.println(a); 
  }
}

--

Now following the instructions in the notes we create a Comparable and a Collections and provide a sort. 

// http://silo.cs.indiana.edu:8346/c212/sum2019/0611a.phps
// http://silo.cs.indiana.edu:8346/spr2012/04242012/one.phps

import java.text.*;
import java.util.*;

interface Comparable<T> { 
  int compareTo(T other);
}

--

import java.util.ArrayList;

class Collections {
  static <T extends Comparable<T>> void sort(ArrayList<T> a) {
    boolean sorted;
    do {
      sorted = true;
      for (int i = 0; i < a.size() - 1; i++) {
        if ((a.get(i)).compareTo(a.get(i+1)) > 0) {
          sorted = false;
          T temp = a.get(i);
          a.remove(i);
          a.add(i+1, temp);
        }
        System.out.println("I am sorting: " + a); 
      }
      System.out.println( Collections.toString(a) );
    } while ( ! sorted );
  }

  static <E> String toString(ArrayList<E> a) {
    String result = "";
    for (E e : a)
      result += e + ", ";
    return result.substring(0, result.length() - 2);
  }

}

--

public class Candidate implements Comparable<Candidate> {
  public int compareTo(Candidate other) {
    return 0; 
  }
  public Candidate(String name, int votes) {
    this.name = name;
    this.votes = votes;
  }
  private String name;
  private int votes; 
  public String toString() {
    return this.name + ":" + this.votes; 
  }
}

--

import java.io.File; 
import java.util.Scanner; 
import java.util.Map; 
import java.util.HashMap; 
import java.util.ArrayList;
// import java.util.Collections;

public class Election {
  public static void main(String[] args) throws Exception {
    String fileName = args[0]; 
    File file = new File(fileName); 
    Scanner read = new Scanner(file); 
    Map<String, Integer> m = new HashMap<String, Integer>(); 
    // https://docs.oracle.com/javase/8/docs/api/java/util/Scanner.html#Scanner-java.io.File-
    while (read.hasNext()) {
      String word = read.next(); 
      // System.out.println( word ); 
      if (m.get(word) == null) {
        m.put(word, 1);  
      } else { 
        m.put(word, 1 + m.get(word)); 
      }
    }
    System.out.println( m ); 
    ArrayList<Candidate> a = new ArrayList<Candidate>(); 
    // https://docs.oracle.com/javase/8/docs/api/java/util/Map.html#keySet--
    for (String key : m.keySet()) {
      System.out.println( key + ": " + m.get(key) );  
      a.add(new Candidate( key , m.get(key) )); 
    }
    System.out.println(a); 
    Collections.sort(a); 
    System.out.println(a); 
  }
}

--

Your goal to change the sort so it calculates with merge sort instead of bubble sort as now.