As per the problem statement I have solve the problem. Please let
me know if you have any doubts or you want me to modify the answer.
And if you find this answer useful then don't forget to rate my
answer as thumps up. Thank you! :)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
import javax.swing.*;
import java.util.StringTokenizer;
import java.text.DecimalFormat;
public class TestStatistics {
public static void main(String[] args)
{
String userInput = JOptionPane.showInputDialog(null, "Please enter Data <separated by commas>: ");
//string tokenizer to
tokenize the user entered string
StringTokenizer
stringTokenizer = new StringTokenizer(userInput, ",");
//result for required
decimal places
int decimalplaces =
Integer.parseInt(JOptionPane.showInputDialog(null, "Enter the
Number of decimal places that the result is required: "));
String string =
"#.";
for(int i = 0; i <
decimalplaces; i++)
string += "0";
DecimalFormat
decimalFormat = new DecimalFormat(string);
int numberValues =
stringTokenizer.countTokens();
double[] data = new
double[numberValues];
for(int i = 0; i <
numberValues; i++)
data[i] = Double.parseDouble(stringTokenizer.nextToken());
Statistics statistics = new Statistics(data, numberValues);
double[]
statisticData = statistics.getOrigData(),
statsSdata = statistics.getSortedData(),
statsStaticSdata = Statistics.computeSortedData(data);
String printData = "" +
statisticData[0],
printInstanceMethodData = "" + statsSdata[0],
printStaticMethodData = "" + statsStaticSdata[0];
for(int i = 1; i <
numberValues; i++)
{
printData += ", " + statisticData[i];
printInstanceMethodData += ", " + statsSdata[i];
printStaticMethodData += ", " + statsStaticSdata[i];
}
//print the out
out
JOptionPane.showMessageDialog(null,
"Original Data:\n" +
printData +
"\n\nResults Using Instance Methods:\n" +
"\nSorted Data:\n" +
printInstanceMethodData +
"\nMin Value: " + decimalFormat.format(statistics.findMin())
+
"\nMax Value: " + decimalFormat.format(statistics.findMax())
+
"\nMean: " + decimalFormat.format(statistics.findMean()) +
"\nMedian: " + decimalFormat.format(statistics.findMedian()) +
"\n\nResults Using Static Methods:\n" +
"\nSorted Data:\n" +
printStaticMethodData +
"\nMin Value: " + decimalFormat.format(Statistics.computeMin(data))
+
"\nMax Value: " + decimalFormat.format(Statistics.computeMax(data))
+
"\nMean: " + decimalFormat.format(Statistics.computeMean(data))
+
"\nMedian: " + decimalFormat.format(Statistics.computeMedian(data))
+
"\nThe Total number of Statistics objects\ncreated during
execution: " +
Statistics.count);
}
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
import java.util.*;
//class statistics
public class Statistics {
private double[] data;
private double[] sdata;
private int size;
public static int count = 0;
//constructor with parameters
public Statistics(double[] data, int size)
{
count++;
this.size = size;
this.data = new
double[size];
System.arraycopy(data, 0, this.data, 0, size);
sdata = new
double[size];
System.arraycopy(data,
0, sdata, 0, size);
Arrays.sort(sdata);
}
//method to get original data to perform
operations
public double[] getOrigData() {
double[] originalData =
new double[size];
System.arraycopy(data,
0, originalData, 0, size);
return
originalData;
}
//method to get sorted data
public double[] getSortedData() {
double[] sortedData =
new double[size];
System.arraycopy(sdata,
0, sortedData, 0, size);
return sortedData;
}
//method to find min
public double findMin() {
return sdata[0];
}
//method to find max
public double findMax() {
return sdata[size -
1];
}
//method to find mean
public double findMean() {
double sum = 0;
for(double d :
data)
sum += d;
return sum / size;
}
//method to find median
public double findMedian() {
return ((sdata[(size /
2)] + sdata[(size - 1) / 2]) / 2.0);
}
//method to compute Sorted Data
public static double[]
computeSortedData(double[] data) {
double[] sData = new
double[data.length];
System.arraycopy(data,
0, sData, 0, data.length);
Arrays.sort(sData);
return sData;
}
//method to compute min
public static double computeMin(double[] data)
{
double min =
data[0];
for(int i = 0; i <
data.length; i++)
if(data[i] < min)
min = data[i];
return min;
}
//method to compute max
public static double computeMax(double[] data)
{
double max =
data[0];
for(int i = 0; i <
data.length; i++)
if(data[i] > max)
max = data[i];
return max;
}
//method to compute mean
public static double computeMean(double[] data)
{
double sum = 0;
for(int i = 0; i <
data.length; i++)
sum += data[i];
return(sum /
data.length);
}
//method to compute median
public static double computeMedian(double[]
data) {
double[] sData =
computeSortedData(data);
return
((sData[(data.length / 2)] + sData[(data.length - 1) / 2]) /
2.0);
}
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Program Output :
pls help java ASAP!!!!!!! Topic String Tokenizer Static Methods Static Variables Primitive Arrays Description Enhance the...
need help editing or rewriting java code, I have this program running that creates random numbers and finds min, max, median ect. from a group of numbers,array. I need to use a data class and a constructor to run the code instead of how I have it written right now. this is an example of what i'm being asked for. This is my code: import java.util.Random; import java.util.Scanner; public class RandomArray { // method to find the minimum number in...
1. What is the output when you run printIn()? public static void main(String[] args) { if (true) { int num = 1; if (num > 0) { num++; } } int num = 1; addOne(num); num = num - 1 System.out.println(num); } public void addOne(int num) { num = num + 1; } 2. When creating an array for primitive data types, the default values are: a. Numeric type b. Char type c. Boolean type d. String type e. Float...
C# programming 50 pts Question 2:2 1- Create the base class Book that has the following instance variables, constructor, and methods title (String) isbn (String) authors (String) publisher (String) edition ( int) published year (int) Constructor that takes all of the above variables as input parameters. set/get methods ToString method// that return sting representation of Book object. 2-Create the sub class New_Book that is derived from the base class Book and has the following instance variables, constructor, and methods: title...
This is a java homework for my java class. Write a program to perform statistical analysis of scores for a class of students.The class may have up to 40 students.There are five quizzes during the term. Each student is identified by a four-digit student ID number. The program is to print the student scores and calculate and print the statistics for each quiz. The output is in the same order as the input; no sorting is needed. The input is...
I need to create a code for this prompt: In this project we will build a generic UserInput class for getting keyboard input from the user. Implementation: The class UserInput is a 'Methods only' class, and all the methods should be declared static. Look at the TestScanner.java program at the bottom of this page that inputs a string, int and double. It shows you how to use Scanner class to get input from the keyboard. Write FOUR simple methods, one...
You will write three static methods to manipulate an input String in different ways using various String methods. You need to provide the code for each of the three static methods in class StringPlay (requirements for each listed below). You will also change the control statement in the test harness to allow for variations in the sentinel value. You need to modify the loop control condition in Lab09.java so that user inputs of ‘finish’, “FINISH”, “FiniSH”, “fINISH”, etc. will end...
Write four overloaded methods called randomize. Each method will return a random number based on the parameters that it receives: randomize() - Returns a random int between min and max inclusive. Must have two int parameters. randomize() - Returns a random int between 0 and max inclusive. Must have one int parameter. randomize() - Returns a random double between min and max. Must have two double parameters. randomize() - Returns a random double between 0 and max. Must have one...
import java.util.LinkedList; public class testprintOut { private static LinkedList[] array; public static void main(String[] args) { int nelems = 5; array = new LinkedList[nelems]; for (int i = 0; i < nelems; i++) { array[i] = new LinkedList<String>(); } array[0]=["ab"]; System.out.println(array[0]); } } //I want to create array of linked lists so how do I create them and print them out efficiently? //Syntax error on token "=", Expression expected after this token Also, is this how I can put them...
I need help making this work correctly. I'm trying to do an array but it is drawing from a safeInput class that I am supposed to use from a previous lab. The safeInput class is located at the bottom of this question I'm stuck and it is not printing the output correctly. The three parts I think I am having most trouble with are in Bold below. Thanks in advance. Here are the parameters: Create a netbeans project called ArrayStuff...
Let’s build a dynamic string tokenizer! Start with the existing template and work on the areas marked with TODO in the comments: Homework 8 Template.c Note: If you turn the template back into me without adding any original work you will receive a 0. By itself the template does nothing. You need to fill in the code to dynamically allocate an array of strings that are returned to the user. Remember: A string is an array. A tokenizer goes through...