Question

In: Computer Science

(JAVA) Implement a ‘runnable’ Class called “NumericAnalyzer”. Here’s the functional behavior that must be implemented. NumericAnalyzer...

(JAVA)

Implement a ‘runnable’ Class called “NumericAnalyzer”. Here’s the functional behavior that must be implemented.

  • NumericAnalyzer will accept a list of 1 or more numbers as command line arguments. These numeric values do not need to be ordered (although you’ll need to display these values sorted ascendingly). NOTE: Don’t prompt the user for input – this is an exercise passing values to your program via the command line!
  • Error checking: if the user fails to pass in parameters, the program will display an error message (of your choice) and exit early.
  • The main() method’s String [] args argument values must be converted and assigned to a numeric/integer array.
  • Your program will display the following information about the numbers provided by the user:
    1. This list of numbers provided by the user sorted ascendingly.
    2. The size of number list (the number of numbers!)
    3. The average or mean value.
    4. The median - the middle value of the set of numbers sorted. (Simple Algorithm: index = the length of the array divided by 2).
    5. The min value.
    6. The max value.
    7. The sum
    8. The range: the difference between the max and min
    9. Variance: Subtract the mean from each value in the list. This gives you a measure of the distance of each value from the mean. Square each of these distances (and they’ll all be positive values), add all of the squares together, and divide that sum by the number of values (that is, take the average of these squared values) .
    10. Standard Deviation: is simply the square root of the variance.

Solutions

Expert Solution

Please find the below well-commented code:

Code text:

import java.util.*;
import java.lang.*;

class NumericAnalyzer {
   void sortedList(int[] list){                                   //sorts the list
       Arrays.sort(list);
       System.out.print("User list sorted ascendingly: ");
       for(int i = 0;i < list.length; i++)
           System.out.print(list[i] + " ");                       //print the elements of list
       System.out.print("\n");
   }
  
   void sizeOfTheList(int[] list){                                   //to print the size of the list
       System.out.println("The Size of the List:"+list.length);
   }
  
   void averageOrMean(int[] list){                                   //prints average of the list
       System.out.print("Average Value of the List:");
       int sum=0;
       for(int i = 0;i < list.length; i++)
           sum=sum+list[i];                                       //calculate the sum
       System.out.println((sum+0.0)/list.length);                   //print the median
   }
  
   void median(int[] list){
       Arrays.sort(list);
       System.out.print("The Median of the List:");              
       System.out.println(list[list.length/2]);                   //Prints median
   }
  
   void min(int[] list){                                           //min element
       Arrays.sort(list);
       System.out.println("Minimum value of the list: " + list[0]);  
   }
  
   void max(int[] list){                                           //max element
       Arrays.sort(list);
       System.out.println("Minimum value of the list: " + list[list.length-1]);
   }
  
   void sum(int[] list){                                           //print sum of the list
       int sum=0;
       for(int i = 0;i < list.length; i++)
           sum=sum+list[i];
       System.out.println("Sum of list is : " + sum);
   }
  
   void range(int[] list){                                           //print the range
       Arrays.sort(list);
       System.out.println("The range : " + (list[list.length] - list[0]));
   }
  
   void variance(int[] list){                                       //function to print the variance
       Arrays.sort(list);
       int sum=0,squaredSum = 0;
       for(int i = 0;i < list.length; i++)
           sum=sum+list[i];
      
       int mean = sum/list.length;
      
       for(int i = 0;i < list.length;i++){
           list[i] = list[i] - mean;
           list[i] = list[i]*list[i];
           squaredSum = squaredSum + list[i];                       //calculate the squared sum
       }
      
       System.out.println("The variance : "+ ((squaredSum+(0.0))/list.length));   //print the variance
   }
  
   void standardDeviation(int[] list){                               //function to print the variance
       Arrays.sort(list);
       int sum=0,squaredSum = 0;
       for(int i = 0;i < list.length; i++)                          
           sum=sum+list[i];
      
       int mean = sum/list.length;
      
       for(int i = 0;i < list.length;i++){
           list[i] = list[i] - mean;
           list[i] = list[i]*list[i];
           squaredSum = squaredSum + list[i];
       }
       double variance = (squaredSum+0.0)/list.length;                  
      
       System.out.println("Standard Deviation: " + Math.sqrt(variance));   //print the squared sum
   }
}


public class NumericAnalyzerMain{
   public static void main(String [] args){
       if(args.length == 0){
           System.out.println("ERROR****Please pass in some arguments\n");   //error if no command line args
           System.exit(1);
       }
      
       int [] list = new int[args.length];
      
       try{                                                               //will raise error if command line args is not
           for(int i = 0; i < args.length; i++){                           //integer
               list[i] = Integer.parseInt(args[i]);                  
           }
       }
       catch (NumberFormatException nfe) {
System.out.println("The argument must be an integer/numeric.");
System.exit(1);
}
      
       NumericAnalyzer numericAnalyzer = new NumericAnalyzer();           //instance of NumericAnalyzer
      
       //call the individual methods
      
       numericAnalyzer.sortedList(list);
      
       numericAnalyzer.sizeOfTheList(list);
      
       numericAnalyzer.averageOrMean(list);
      
       numericAnalyzer.median(list);
      
       numericAnalyzer.min(list);
      
       numericAnalyzer.max(list);
      
       numericAnalyzer.sum(list);
      
       numericAnalyzer.variance(list);
      
       numericAnalyzer.standardDeviation(list);
   }
}

Output:


Related Solutions

Java programming language should be used Implement a class called Voter. This class includes the following:...
Java programming language should be used Implement a class called Voter. This class includes the following: a name field, of type String. An id field, of type integer. A method String setName(String) that stores its input into the name attribute, and returns the name that was just assigned. A method int setID(int) that stores its input into the id attribute, and returns the id number that was just assigned. A method String getName() that return the name attribute. A method...
JAVA - Design and implement a class called Flight that represents an airline flight. It should...
JAVA - Design and implement a class called Flight that represents an airline flight. It should contain instance data that represent the airline name, the flight number, and the flight’s origin and destination cities. Define the Flight constructor to accept and initialize all instance data. Include getter and setter methods for all instance data. Include a toString method that returns a one-line description of the flight. Create a driver class called FlightTest, whose main method instantiates and updates several Flight...
Implement Java source code for a class called Temperature that does the following: a. Prompts the...
Implement Java source code for a class called Temperature that does the following: a. Prompts the user to input a temperature b. Prints “Too Hot!” when the input temperature is above 75 c. Prints “Too Cold!” when the input temperature is below 40 d. Prints “Just Right!” when the input temperature is 40 to 75 e. Be precise, include comments, prologue, etc. if needed.
using Java Implement a class called Binomial_Coefficient o Your class has 2 int attributes, namely K...
using Java Implement a class called Binomial_Coefficient o Your class has 2 int attributes, namely K and n o Create an overloaded constructor to initialize the variables into any positive integers such that n > k > 0o Create a method that calculates the value of binomial coefficient, C(n,k) , using the following rule: ▪ For an array of size (n+1) X (k+1) ▪ Array [n][k] = Array[n-1][ k-1]+ Array[n-1] [k]▪ Array[n][0]= Array[n][n] = 1 ▪ Hence, C(n,k) = array...
in JAVA: implement a class called tree (from scratch) please be simple so i can understand...
in JAVA: implement a class called tree (from scratch) please be simple so i can understand thanks! tree(root) node(value, leftchild,rightchild) method: insert(value)
Use Java programming to implement the following: Implement the following methods in the UnorderedList class for...
Use Java programming to implement the following: Implement the following methods in the UnorderedList class for managing a singly linked list that cannot contain duplicates. Default constructor Create an empty list i.e., head is null. boolean insert(int data) Insert the given data into the end of the list. If the insertion is successful, the function returns true; otherwise, returns false. boolean delete(int data) Delete the node that contains the given data from the list. If the deletion is successful, the...
Write a class in Java called 'RandDate' containing a method called 'getRandomDate()' that can be called...
Write a class in Java called 'RandDate' containing a method called 'getRandomDate()' that can be called without instantiating the class and returns a random Date between Jan 1, 2000 and Dec 31, 2010.
JAVA * create Q3 class to implement comparator for a TreeSet. The purpose of       ...
JAVA * create Q3 class to implement comparator for a TreeSet. The purpose of        * the comparator is to compare the alphabetic order of integers. With Q3,        * the order of Integer elements will be sort according to the order of        * digit Unicode.        * For example, the value of {11,3,31,2} will return {11,2,3,31}        * NOTE: You don't need to compare each digit one by one. Just compare them System.out.println("Q3...
Java the goal is to create a list class that uses an array to implement the...
Java the goal is to create a list class that uses an array to implement the interface below. I'm having trouble figuring out the remove(T element) and set(int index, T element). I haven't added any custom methods other than a simple expand method that doubles the size by 2. I would prefer it if you did not use any other custom methods. Please use Java Generics, Thank you. import java.util.*; /** * Interface for an Iterable, Indexed, Unsorted List ADT....
Suppose the interface and the class of stack already implemented, Write application program to ( java)...
Suppose the interface and the class of stack already implemented, Write application program to ( java) 1- insert 100 numbers to the stack                         2- Print the even numbers 3- Print the summation of the odd numbers
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT