In: Computer Science
Suppose you have a set of data as shown below:
{3, 25, 33, 21, 55, 43, 78, 31, 33, 75, 43, 11, 36, 4, 10, 99, A, B, C}
Write a Java class called "DataAnalysis" that has the following methods:
Program:
import java.util.*;
public class DataAnalysis{
static Set<String> Data_NaN(Set<String>
set){
Set<String> set2 = new
HashSet<String>();
for (String temp : set) {
temp = temp.replaceAll(
"[^0-9]", "");
if(!(set.isEmpty())){
set2.add(temp);
}
}
return set2;
}
public static void main(String args[])
{
// create empty set
Set<String> set = new HashSet<String>();
// {3, 25, 33, 21, 55, 43, 78, 31, 33, 75, 43, 11, 36, 4, 10, 99,
A, B, C}
// add values one by one in set
set.add("03");
set.add("25");
set.add("33");
set.add("21");
set.add("55");
set.add("43");
set.add("78");
set.add("31");
set.add("33");
set.add("75");
set.add("43");
set.add("11");
set.add("36");
set.add("04");
set.add("10");
set.add("99");
set.add("A"); set.add("B"); set.add("C");
// print input set
System.out.println("Set: " + set);
// call funtion Data_NaN to filter out non-numerical data
System.out.println("After filtering nonnumerical data- Set:
"+Data_NaN(set));
// call funtion Data_Min to calculate min value
System.out.println("Minimum number from set is=
"+Data_Min(set));
}
static String Data_Min(Set<String> set) {
String obj =
Collections.min(set);
return obj;
}
}
Output:
Set: [78, A, B, C, 55, 04, 36, 33, 25, 11, 03, 21, 10, 43, 31,
99, 75]
After filtering nonnumerical data- Set: [, 78, 55, 04, 36, 33, 25,
11, 03, 21, 10, 43, 31, 99, 75]
Minimum number from set is= 03