Suppose we have a Java type called Contract which represents business contracts. Among the method headers in class Contract are the following:
public Date finish()
returns an object representing the date on which a contract finishes.
public void update(Date d)
changes the state of the object on which it is called to represent changes in contract terms which apply after the date given by the argument.
public int payment(Date d)
returns the payment due on the date given as its argument, this will always be an integer which is greater than 0.
public Set<Contract> subcontracts()
returns a set representing all the subcontracts of the contract represented by the object on which this method is called.
One of the questions asked:
Write an instance method to go in class Contract called biggestPayment. When called on an object representing a contract, this method should take a Date argument and return the representation of whichever subcontract has the biggest payment due on the date given. If the contract has no subcontracts, the object on which the method is called should be returned.
My first problem is I can't figure out how to return the Contract object with the max value..or if the contract has no subcontracts, the object on which the method is called should be returned...
Here's what I have so far.. but it doesn't like that I called method payment from the inner class:
public Contract biggestPayment(Date d)
{
List<Contract> clist = new ArrayList<Contract>(subc);
Collections.sort(clist, new Comparator<Contract>()
{
public int compare(Contract c1, Contract c2)
{
c1.payment(d).compareTo(c2.payment(d));
}
});
.......
}
Any help would be appreciated.