Assignment #3: Interfaces, Function Objects

This assignment has two parts.

Interfaces

Go back to the previous assignment, that had the Ticket hierarchy. Add the functionality described here: Some tickets can be upgraded. If a ticket is Upgradeable it has a method named upgrade. For this assignment, invoking upgrade will print the message "you've been upgraded!". Design an appropriate interface, and make StudentAdvanceTicket and WalkupTicket upgradeable. Write a method that steps through the collection of Tickets and invokes upgrade on all the appropriate tickets.

Function Objects

Method transform takes two identically sized-arrays of double as parameters: input and output, and a third parameter representing a function to be applied to the input array. For instance, in the following code fragment:
   double [ ] input = { 1.0, -3.0, 5.0 };
   double [ ] output1 = new double [ 3 ];
   double [ ] output2 = new double [ 3 ];
   double [ ] output3 = new double [ 4 ];

   transform( input, output1, new ComputeSquare( ) );
   transform( input, output2, new ComputeAbsoluteValue( ) );
   transform( input, output3, new ComputeSquare( ) );
The intended result is that output1 contains { 1.0, 9.0, 25.0 }, output2 contains { 1.0, 3.0, 5.0 }, and the third call to transform throws an IllegalArgumentException because the arrays have different sizes. Implement the following components:
  1. An interface that will be used to specify the third parameter to transform.
  2. The transform method (which is a static method). Remember to throw an exception if the input and output arrays are not identically-sized.
  3. The classes ComputeSquare and ComputeAbsoluteValue.