Here is a problem that you can do if you want to get some practice for the final...
Write a Cat class. Its constructor should take a String as its input and store it as the name of the Cat.
In your public static void main(String args) method:
- Create an array of five Cats.
- Create five actual Cats named "Nora", "Heathcliff", "Cuddles", "Gremalkin", and "Charcoal", in that order.
- Print out the contents of the array. This means that your Cat class will need a toString() method. Having toString() return the name of the Cat probably makes sense. This also means that you will need to write a method printCats(Cat cats) in the same class as main(). (What happens if you make the input of printCats an array of Objects instead of an array of Cats? Why do you suppose that happens?)
- Use Arrays.sort() to sort the Cats. Think about what this means in terms of your Cat class. (You will need to implement the Comparable<Cat> interface.)
- Print out the contents of the array again to make sure that the sort worked.