reset password
Author Message
ladodgersfan
Posts: 13
Posted 13:38 May 03, 2014 |

is the compare method just comparing if the two objects are the same and return 1 if they are the same or something like that. also what are we using the Calculable interface for, I haven't used it since the add and subtract methods take care of the additions and subtractions

kknaur
Posts: 540
Posted 15:18 May 03, 2014 |

compareTo Comes from the Comparable interface (which you need to implement) and allows the built in sorting algorithms to compare objects and sort them.  It should return a negative number if one object is less than the other, 0 if the two objects are equal, or a positive number if the one object is greater than the other. 

Also, the add and subtract methods come from the Calculable interface which your classes need to implement.  We use the interface to give unrelated classes similar functionality.  In this case you could store all Time and Money objects in an array or arraylist of Calculable type.  When you learn generics, you will see how you create generic methods that work with objects of an interface type. 

Interfaces will be more applicable when we start talking about designing Graphical User Interfaces.