Starting from:

$30

Assignment 7 Generic ArrayTester class

Assignment 7 (Extra Credit)

Objective
This assignment will give you practice with using generic classes in Java.
Task
Write a generic ArrayTester class that contains an array and a CustomTest and prints or counts
the elements of the array if they pass the test. Also write a couple of CustomTest classes. Your
final jar file will contain the following source code files:
 ArrayTester.java
 CustomTest.java
 IsEven.java
 AllLower.java
 GreaterThan.java
 ECTester.java
All of the above will be created by you except ECTester.java, which you should
download (and turn in an unedited version of) from the Canvas site for Assignment 7.
Each file should have a comment including your name at the top of the file. Each file
should also have appropriate comments throughout.
Requirements
1. CustomTest<T> interface: This should be a generic interface that requires a single
method, test. This method should take in an element of the generic type T and return a
boolean. This function will be used to determine whether a particular object of type T
passes the test or not.
2. ArrayTester<T> class: This should be a generic class. It should contain two member
data: an array of type T and an object of type CustomTest<T> called tester. It should
contain at least three methods:
 Constructor – A single constructor, which should take in a parameter of type T[] and a
second parameter of type CustomTest<T>. This constructor should assign these
parameters to the member data of the class. It should also sort the array based on its
natural ordering.
 printIfValid() – This method should print out each element of the array that
passes the test given by tester. Each element should be separated by a single space and
the entire list should be followed by a new line (see sample output). It should not return
anything.
 countIfValid() – This method should return an integer that counts the number of
elements in the array that pass the test given by tester.
1
3. IsEven<T> class: This should be a generic class that implements the CustomTest<T>
interface. It should accept as a type parameter any class that is a subclass of Number. The
test in this class should return true if the integer value of the object passed in is even, false
otherwise.

4. AllLower class: This should be a non-generic class that implements the
CustomTest<T> interface. This will test objects of type String and the test method
should return true if the letters in the String are all lowercase.

5. GreaterThan<T> class: This should be a generic class that implements the
CustomTest<T> interface. It should accept as a type parameter any class that is
guaranteed to have the CompareTo(T) method. This class will have one piece of member
data of type T. That value of that piece of member data should be the same as a parameter
passed into the constructor (so you should have a one-parameter constructor). The test in
this class should return true if the object passed in is considered greater than the piece of
member data (by the type’s natural ordering), false otherwise.

6. Other Requirements:
 When you run the ECTester program, your output should match the sample output
exactly
Sample Output
This is exactly the output that an unedited ECTester program should have:
There are 5 valid integers
They are:
2 4 6 8 10
There are 5 valid doubles
They are:
0.2 4.2 10.0001 12.2 123456.0
There are 4 valid strings
They are:
a desk? is raven
There are 6 integers greater than 4
They are:
5 6 7 8 9 10
There are 5 doubles greater than 4.5
They are:
5.4 10.0001 11.9 12.2 123456.0
There are 3 strings greater than "last"
They are:
liKe raven wriTing
2
Submitting
Pack all of your files (class files and source code) into a fully runnable JAR file called ec.jar.
The main program that the jar file should execute should be an unedited version of the
ECTester.java file. I should be able to run the main() method from your file with the
command:

java -jar ec.jar

Submit your jar file via the Canvas submission link for Assignment 7.
3

More products