Programming Exercises

6.1 Declare an interface called Function that has a method named evaluate that takes an int parameter and returns an int value.>

Create a class Half that implements Function. Make the implementation of the method evaluate() return the value obtained by dividing the int argument by 2.

In a client, create a method that takes an arbitrary array of int values as parameter and returns an array that has the same length, but the value of an element in the new array is half that of the value in the corresponding element in the array passed as parameter. Let the implementation of this method create an instance of Half and use this ...

Get Programmer's Guide to Java™ Certification, A: A Comprehensive Primer, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.