You will work on Java Generics in the Final exam. Please follow the instructions below in your
1. Design a generic class Container with the following specifications:
a) Has a data field of type List of the same generic type as the Container
b) Has a parameterized constructor that takes a list of the same generic type as the
c) Has an apply method that takes a Java interface of the same generic type as the
Container that applies this interface’s single function to all Container’s elements. It then
returns this new Container.
d) Has a filter method that takes a Java interface with a binary Boolean function that
returns a new Container with the elements of the Container that satisfies the binary
Boolean function (included in the Java interface).
e) Has a doItOnAll method that takes a Java interface with a void function that applies the
only void function to all members of the Container and does not return anything back.
f) Has a toList method that returns a list of the same generic type as the Container. Note
that Container is not a list but the elements of which are stored in a list.
2. Have the following Java interfaces that you need to use with the above Container. More on
these interfaces (how to implement and use them in (3 and 4)).
a) A generic Java interface with a single void function that applies this function to an
element passed to it.
b) A generic Java interface with a single boolean binary function (of arguments’ type T and
U). The binary function uses these two arguments and return true or false.
c) A generic Java interface with a single value-returning function that applies its only
function to an element and returns a new element of the same type.
3. Design the following classes implementing the interfaces given in (2).
a) A Double class that implements (2-c) and as its name implies doubles its integer
b) A Square class that implements (2-c) and its name implies squares its integer argument.
c) A GreaterThan class that implements (2-b) and returns true if its first integer argument is
greater than its second integer one.
d) A GreaterThan2 class that implements (2-b) and returns true if its first String argument’s
length is greater than its second integer one.
e) A Print Class that implements (2-a) and prints its only argument to the console.
4. Do the following in the main method to test your classes.
a) Create a Container object of type Integer. Populate it with some integers. Then “Double”
and “Square” its elements while returning new Container and printing its elements to the
console. Also, find a new Container whose elements are greater than some integer. Print
it also to the console.
b) Create a Container object of type String. Populate it with some strings. Then obtain a
Container whose elements are longer than 5 characters. Print the elements of this new
Container to the console.
c) Print the elements of any the Containers you obtained in the main using an instance of
İşin Yapılacağı Konum: İSTANBUL
Görevin Başlangıç Tarihi: 09-06-2020
Görevin Bitiş Tarihi: 15-06-2020