Question: a. Define a Java interface named SortableInterface. A class that implements this interface allows creation of an object that holds an array of objects of
a. Define a Java interface named SortableInterface. A class that implements this interface allows creation of an object that holds an array of objects of a specified type. The SortableInterface interface should require the add method to add an object to the array and the sort method to sort the objects in the array. The actual type of the objects in the array is specified when the SortableInterface object is instantiated. Therefore, both the SortableInterface interface and the classes that implement it should be generic. Suppose a class named StringSort implements the SortableInterface interface. A test driver application is shown here. Its output would be "bob jim michael" and "1000 2000 5000."
public class Sample { public static void main (String[] args) { SortableInterface a
a.add("bob");
a.add("jim");
a.add("michael");
a.sort();
System.out.print(a.toString());
SortableInterface b
b.add(new BankAccount(1000));
b.add(new BankAccount(5000));
b.add(new BankAccount(2000));
b.sort();
System.out.print(b.toString());
}
}
b. Create a class called StringSort that implements the SortableInterface interface. This class should use an array to hold String objects.
c. Create a class called BankAccountSort that implements the SortableInterface interface. This class should use an array to hold BankAccount objects. We assume that the BankAccount class provides a constructor that accepts as an argument the initial balance.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
