Question

In: Computer Science

import java.util.*;    public class DataAnalysis{    static Set<String> Data_NaN(Set<String> set){        Set<String> set2 =...

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: After filtering nonnumerical data: [33, 55, 11, 99, , 78, 25, 36, 3, 4, 31, 75, 21, 43, 10]
Minimum value After filtering nonnumerical data:

Question:. this is a dataset given{3, 25, 33, 21, 55, 43, 78, 31, 33, 75, 43, 11, 36, 4, 10, 99, A, B, C} why Data min method does not print any thing? I need to find maximum value, average value, median, mode, order it small to large using numerical data of given dataset in separate methods.

Solutions

Expert Solution


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");
// 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(Data_NaN(set)));

        }

        static String Data_Min(Set<String> set) {
                // here it will compare the numbers as strings so we will not get the correct
                // so we should convert it as int and find min
                int min = Integer.MAX_VALUE;
                for (String s : set) {
                        if (s.trim().length() != 0) {
                                int i = Integer.parseInt(s);
                                if (i < min)
                                        min = i;
                        }
                }
                return Integer.toString(min);
        }
}

NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.

I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME


Related Solutions

In java. Please explain. Consider the following program: } import java.util.*; public class Chapter7Ex12 { static...
In java. Please explain. Consider the following program: } import java.util.*; public class Chapter7Ex12 { static Scanner console = new Scanner(System.in); public static void main(String[] args) { double num1; double num2; System.out.print("Enter two integers: "); num1 = console.nextInt(); num2 = console.nextInt(); System.out.println(); if (num1 != 0 && num2 != 0) System.out.printf("%.2f\n", Math.sqrt(Math.abs(num1 + num2 + 0.0))); else if (num1 != 0) System.out.printf("%.2f\n", Math.floor(num1 + 0.0)); else if (num2 != 0) System.out.printf("%.2f\n",Math.ceil(num2 + 0.0)); else System.out.println(0); }} a. What is the...
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Exercise { public static void main(String[] args) {...
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Exercise { public static void main(String[] args) { Scanner input=new Scanner(System.in); int[] WordsCharsLetters = {0,1,2}; while(input.hasNext()) { String sentence=input.nextLine(); if(sentence!=null&&sentence.length()>0){ WordsCharsLetters[0] += calculateAndPrintChars(sentence)[0]; WordsCharsLetters[1] += calculateAndPrintChars(sentence)[1]; WordsCharsLetters[2] += calculateAndPrintChars(sentence)[2]; } else break; } input.close(); System.out.println("Words: " + WordsCharsLetters[0]); System.out.println("Characters: " + WordsCharsLetters[1]); System.out.println("Letters: " + WordsCharsLetters[2]); } static int[] calculateAndPrintChars(String sentence) { int[] WCL = new int[3]; String[] sentenceArray=sentence.split(" "); WCL[0] = sentenceArray.length; int letterCount=0; for(int i=0;i<sentence.length();i++) { if(Character.isLetter(sentence.charAt(i))) letterCount++; } WCL[1]...
import java.util.Stack; import java.util.Scanner; class Main { public static void main(String[] args)    {       ...
import java.util.Stack; import java.util.Scanner; class Main { public static void main(String[] args)    {        Stack<Integer> new_stack = new Stack<>();/* Start with the empty stack */        Scanner scan = new Scanner(System.in);        int num;        for (int i=0; i<10; i++){//Read values            num = scan.nextInt();            new_stack.push(num);        } System.out.println(""+getAvg(new_stack));    }     public static int getAvg(Stack s) {        //TODO: Find the average of the elements in the...
import java.util.Stack; import java.util.Scanner; class Main { public static void main(String[] args)    {       ...
import java.util.Stack; import java.util.Scanner; class Main { public static void main(String[] args)    {        Stack<Integer> new_stack = new Stack<>();/* Start with the empty stack */        Scanner scan = new Scanner(System.in);        int num;        for (int i=0; i<10; i++){//Read values            num = scan.nextInt();            new_stack.push(num);        }        int new_k = scan.nextInt(); System.out.println(""+smallerK(new_stack, new_k));    }     public static int smallerK(Stack s, int k) {       ...
INSERT STRING INTO SEPARATE CHAIN HASHTABLE & ITERATE THROUGH HASHTABLE: JAVA _________________________________________________________________________________________________________________ import java.util.*; public class...
INSERT STRING INTO SEPARATE CHAIN HASHTABLE & ITERATE THROUGH HASHTABLE: JAVA _________________________________________________________________________________________________________________ import java.util.*; public class HashTable implements IHash { // Method of hashing private HashFunction hasher; // Hash table : an ArrayList of "buckets", which store the actual strings private ArrayList<List<String>> hashTable; /** * Number of Elements */ private int numberOfElements; private int numberOfBuckets; /** * Initializes a new instance of HashTable. * <p> * Initialize the instance variables. <br> * Note: when initializing the hashTable, make sure to...
import chapter6.date.SimpleDate; import java.util.Scanner; public class SimpleDateTestDefault { public static void main(String[] args) { Scanner stdin...
import chapter6.date.SimpleDate; import java.util.Scanner; public class SimpleDateTestDefault { public static void main(String[] args) { Scanner stdin = new Scanner(System.in); SimpleDate d1 = new SimpleDate(); SimpleDate d2 = new SimpleDate(stdin.nextInt(), stdin.nextInt(), stdin.nextInt()); System.out.println(d1); System.out.println(d2); System.out.println(d1.before(d2)); System.out.println(d2.before(d1)); } } Implement SimpleDate class in chapter6.date package with the following attributes: day, (int type,  private) month, (int type,  private) year (int type,  private) The class should have the following methods: a constructor with three parameters: year, month, and day a constructor with no parameters which initialize the...
------------------------------------------------------------------------------------ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input =...
------------------------------------------------------------------------------------ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); int result = 0; System.out.print("Enter the first number: "); int x = input.nextInt(); System.out.print("Enter the second number: "); int y = input.nextInt(); System.out.println("operation type for + = 0"); System.out.println("operation type for - = 1"); System.out.println("operation type for * = 2"); System.out.print("Enter the operation type: "); int z = input.nextInt(); if(z==0){ result = x + y; System.out.println("The result is " + result); }else...
import java.util.Scanner; public class Lab9Q3 { public static void main (String [] atgs) { double mass;...
import java.util.Scanner; public class Lab9Q3 { public static void main (String [] atgs) { double mass; double velocity; double totalkineticEnergy;    Scanner keyboard = new Scanner (System.in); System.out.println ("Please enter the objects mass in kilograms"); mass = keyboard.nextDouble();    System.out.println ("Please enter the objects velocity in meters per second: "); velocity = keyboard.nextDouble();    double actualTotal = kineticEnergy (mass, velocity); System.out.println ("Objects Kinetic Energy: " + actualTotal); } public static double kineticEnergy (double mass, double velocity) { double totalkineticEnergy =...
import java.util.Random; class Conversions { public static void main(String[] args) { public static double quartsToGallons(double quarts)...
import java.util.Random; class Conversions { public static void main(String[] args) { public static double quartsToGallons(double quarts) { return quarts * 0.25; } public static double milesToFeet(double miles) { return miles * 5280; } public static double milesToInches(double miles) { return miles * 63360; } public static double milesToYards(double miles) { return miles * 1760; } public static double milesToMeters(double miles) { return miles * 1609.34; } public static double milesToKilometer(double miles) { return milesToMeters(miles) / 1000.0; } public static double...
Write program in Java import java.util.Scanner; public class Lab7Program { public static void main(String[] args) {...
Write program in Java import java.util.Scanner; public class Lab7Program { public static void main(String[] args) { //1. Create a double array that can hold 10 values    //2. Invoke the outputArray method, the double array is the actual argument. //4. Initialize all array elements using random floating point numbers between 1.0 and 5.0, inclusive    //5. Invoke the outputArray method to display the contents of the array    //6. Set last element of the array with the value 5.5, use...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT