Starting from:

$30

ECE325-Assignment 5 Interfaces Solved

Exercise 1

Comparable
 interface (
java.lang.Comparable
Java defines a ); this interface is a parameterized

interface. We will discuss parameterized classes and interfaces in detail later in the course. For now, you do not need to know too much about parameterization -- just use it.

Read the code in Coffee.java. You are required to complete the class definition to allow collections of coffees to be sorted by the strength.

Find the code from CoffeeTest.java. What imports are required to allow it to compile? And how would I rewrite this class to utilize JUnit? Create a JUnit project as submission.

Exercise 2

Consider the code below. It describes 5 types either classes or interfaces.

U u; G g; B b; Z z; X x;
The following assignments are all legal and compile:

u = z; x = b; g = u; x = u;
However, the following assignments are all illegal and cause compilation errors:
u = b; x = g; b = u; z = u; g = x;
TreeSet
 (
java.util.TreeSet
runTest
Person
 
Person
)
Comparator
Comparator
What can you state about the types and their relationships (to each other)? Provide at least one possible answer.

Exercise 3
The collections library has a class ). It is another parameterised

class which is an example of a sorted set. That is, elements in this set are kept in order. Construct  and PersonCompator to make the  in PersonTest.java successfully

complete. This method checks if Person objects are correctly ordered by their ages (age is the only attribute of PersonComparator is required to implement interface  ( java.util.Comparator ).  is another parameterised interface -parameterization is common in Java.

More products