URGENtt!!
You are asked to write a java class named "Kume". The UML class diagram of the Kume class is as follows.
3
The elements in the set are kept in an ArrayList. The constructor of the class takes an array of int and adds the elements of this array to the ArrayList named al. The add() method adds an integer it takes as a parameter to the get element. The delete() method deletes an Integer object that it takes as a parameter from the get element, returns true if it can be deleted, otherwise false. The print() function prints the elements of the set to the console. The compareTo() method is inherited from the Object class and is suppressed, and compares the get element of the Set object, which it takes as a parameter, with the retrieve element of the current set object in terms of content (the order of the elements is not important). It returns 1 if both sets contain the same elements, 0 otherwise.
Below is a test code that creates two objects from the Kume class and performs various operations on them.
import java.util.ArrayList;
public class Final_question3 {
public static void main(String[] args) {
Kume k1 = new Kume(new int[]{5, 3});
Kume k2 = new Kume(new int[]{3, 2, 5, 7});
k1.print();
k2.print();
if(k1.compareTo(k2) == 1)
System.out.println("The sets are the same");
else
System.out.println("The sets are different");
k1.add(2);
k1.print();
k2.sil(7);
k2.print();
if(k1.compareTo(k2) == 1)
System.out.println("The sets are the same");
else
System.out.println("The sets are different");
}
}
Console output:
Cluster: [5, 3]
Cluster: [3, 2, 5, 7]
Clusters are different
Cluster: [5, 3, 2]
Cluster: [3, 2, 5]
Clusters are the same