It ought to be
implements Comparable<Sheep> . . .
Then you can have Sheep as the type of the parameter to the compareTo method. You can then forget about the class casting, too.
Telling the compiler to implement Comparable<T> will lead the compiler to "believe" that this class has a "natural order."
You realise that two Sheep with the same name length will be left alone by the sort algorithm?
And imagine what will happen if you have a flock of 976 sheep, all with 6 letters in their name. The sort method will leave them all in the same order and the binary search will have no chance of finding them.
Suggest that, if you are comparing by the name field, and name is a
String, and String already implements Comparable<String>, you could try changing the compareTo method to read
return name.compareTo(other.name);
You ought to have a look at the
Object class and read about equals.
You will be in a situation where woolly.equals(obj) and !obj.equals(woolly). The sort and search methods are dependent on the compare, equals (and maybe hashCode) methods being implemented correctly.
The way binary search works is that it finds the middle element by taking myArray.length / 2; if that is equal, then eureka!
If it is "less" (compareTo returns negative) it tries middle / 2, otherwise it tries (middle + length) / 2 and keeps going until it runs out of options or finds something.
What happens if compareTo() returns 0 and equals returns false, I am not sure. Maybe it returns a negative result.