14. Sorting

  • 14. Comparable Intro
  • A class implements the Comparable interface when there is a way to decide whether one object of the class is greater than another. The compareTo method is the way to find out how the two classes compare.

  • 14. Comparable Exercises
  • Exercises from 2018.

  • 14. Comparable Clock
  • Example implementing Comparable for a clock class with hours and minutes.

  • 14 .Comparable Bug
  • A Bug can go one of four directions: “North”, “South”, “East”, and “West”. A bug also has a speed, which is a non-negative integer. Bugs are going to be ordered using both their direction and speed. The “primary” method of ordering bugs will be their direction. We will consider their speed only if their directions are the same. Direction: West < South < East < North Speed: small number < big number You are going to write the code, including a constructor Bug (String direction, int speed).