Question: java problem Let's revisit the class Combination from laboratory 1. Make all the necessary changes to the class Combination (see below) so that it implements
java problem
Let's revisit the class Combination from laboratory 1. Make all the necessary changes to the class Combination (see below) so that it implements the interface java.lang.comparable. public interface Comparable {//Compares this object with the specified object for order.//Returns a negative integer, zero, or a positive integer//as this object is less than equal to, or greater than the//specified object. public int compareTo (E other); } When two Combination objects are compared, the first pair of values is compared first, if the value of this object is smaller than that of the other then the method will return -1, if it is greater, then it will return 1, if those values are equal, then the second pair of values is considered the value -1 or 1 will be returned if the second value of this object is smaller than that of the second, finally those values are also equal then the third pair of values is considered. Comparable is part of a package, called lang, that is imported by default. Therefore, no need to import Comparable. Write a test program for thoroughly testing your implementation. File: Combination.java/** * ITI 152. Introduction l'informatique II (Hiver 2008). * ITI 1121. Introduction to computer Science II (Winter 2008). * * @ author Marcel Turcotte, Universit d'ottawa/University of ottawa */public class Combination { private int first; private int second; private int third; public Combination (int first, int second, int third) { this.first = first; this.second = second; this. third = third; } public boolean equals (object obj) { Combination other = (Combination) obj; return ((other != null) && (first == other. first) && (second == other.second) && (third == other. third)); } public string toString() { return first + " " + second + " " + third; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
