/*
* An object of class StatCalc can be used to compute several simple
statistics
* for a set of numbers. Numbers are entered into the dataset
using
* the enter(double) method. Methods are provided to return the
following
* statistics for the set of numbers that have been entered: The
number
* of items, the sum of the items, the average, and the standard
deviation
*/
public class StatCalc {
private int count; // Number of numbers that have been
entered.
private double sum; // The sum of all the items that
have been entered.
private double squareSum; // The sum of the squares of
all the items.
/**
* Add a number to the dataset. The statistics will be
computed for all
* the numbers that have been added to the dataset
using this method.
*/
public void enter(double num) {
count++;
sum += num;
squareSum += num*num;
}
/**
* Return the number of items that have been entered
into the dataset.
*/
public int getCount() {
return count;
}
/**
* Return the sum of all the numbers that have been
entered.
*/
public double getSum() {
return sum;
}
/**
* Return the average of all the items that have been
entered.
* The return value is Double.NaN if no numbers have
been entered.
*/
public double getMean() {
return sum / count;
}
/**
* Return the standard deviation of all the items that
have been entered.
* The return value is Double.NaN if no numbers have
been entered.
*/
public double getStandardDeviation() {
double mean = getMean();
return Math.sqrt( squareSum/count -
mean*mean );
}
}
//end class StatCalc
// StatCalcMain class
public class StatCalcMain {
public static void main(String[] args) {
StatCalc myStatCalc;
myStatCalc = new StatCalc(); //
create an object of StatCalc class
// create an array of inputs
int arr[] = {5, 7, 12, 23, 3, 2, 8,
14, 10, 5, 9, 13};
// loop to pass the inputs to the
StatCalc object
for(int
i=0;i<arr.length;i++)
myStatCalc.enter(arr[i]);
// Outputs
System.out.println("Count :
"+myStatCalc.getCount());
System.out.println("Mean :
"+myStatCalc.getMean());
System.out.println("Standard
Deviation : "+myStatCalc.getStandardDeviation());
}
}
//end class StatCalcMain
Output:
The following class StatCalc defines a series of methods for computing statistics for a group of...
The following class StatCalc defines a series of methods for computing statistics for a group of numbers. /* * An object of class StatCalc can be used to compute several simple statistics * for a set of numbers. Numbers are entered into the dataset using * the enter(double) method. Methods are provided to return the following * statistics for the set of numbers that have been entered: The number * of items, the sum of the items, the average, and...
Write the definitions of the member functions of the class integerManipulation not given in Example 10-11. Also, add the following operations to this class: Split the number into blocks of n-digit numbers starting from right to left and find the sum of these n-digit numbers. (Note that the last block may not have ndigits. If needed add additional instance variables.) Determine the number of zeroes. Determine the number of even digits. Determine the number of odd digits Also, write a...
The FoodItem.java file defines a class called FoodItem that contains instance variables for name (String) and calories (int), along with get/set methods for both. Implement the methods in the Meal class found in Meal.java public class FoodItem{ private String name; private int calories; public FoodItem(String iName, int iCals){ name = iName; calories = iCals; } public void setName(String newName){ name = newName; } public void setCalories(int newCals){ calories = newCals; } public int getCalories(){ return calories;...
pls help java ASAP!!!!!!! Topic String Tokenizer Static Methods Static Variables Primitive Arrays Description Enhance the last assignment by providing the following additional features: (The additional features are listed in bold below) Class Statistics In the class Statistics, create the following static methods (in addition to the instance methods already provided). • A public static method for computing sorted data. • A public static method for computing min value. • A public static method for computing max value. • A...
import java.util.Scanner; // TASK #1 Add the file I/O import statement here /** This class reads numbers from a file, calculates the mean and standard deviation, and writes the results to a file. */ public class StatsDemo { // TASK #1 Add the throws clause public static void main(String[] args) { double sum = 0; // The sum of the numbers int count = 0; // The number of numbers added double mean = 0; // The average of the...
ble and instance variable, and then use clas 4. Please discuss the difference between class variable and instant variable to complete the following code for the count of number of stud public class Student _//q1: fill this line to create a class variable num. public Student 1/ 22: fill this line to increase num. public static int getNum() return num; public static void main(String[] args) { Student stl=new Student O; Student st2-new Student ; Student st3-new Student ; //q3: fill...
Create a program using the Random class and While loops in Java. The program should generate a random number from 50 through 100. The loop should add the five random numbers generated. On each iteration of the loop the program should print out the number generated, how many numbers have been generated thus far, and the sum so far. On the last iteration, the printout should say the The final total is.... Teach comment the last time I did it:...
Your output should look as follows: DataSet = 10, 27, 32, 34, 35, 44, 48, 49 Descriptive Statistics: Minimum Maximum Range Size Sum Mean Median Standard Deviation Variance Mid Range = 10 = 49 = 39 = 8 = 279 = 34.875000 = 39.500000 = 12.788806 = 163.553571 = 29.5 Enter a integer value to be set in the DataSet: 50 Enter a valid index from the DataSet: 1 DataSet = 10, 32, 34, 35, 44, 48, 49, 50 Value...
We have written the following Class1 class: class Class1 implements SecretInterface { // instance variable private int x = 0; // constructor public Class1(int x) { this.x = x; } // instance methods public double myMethod1(double x, double y) { return x - y; } public void myMethod2(int x) { System.out.println(x); } public String myMethod3(String x) { return "hi " + x; } } We have also written the following Class2 class: class Class2 implements SecretInterface { // instance variable...
The following code below must be able to run using linked list instead of using arrays ------------------------------------------------------------------------------------------------------- #include #include using namespace std; //Class for standard deviation class stdDev { private: int max; double value[100]; double mean; public: double CalMean() { double sum = 0; for (int i = 0; i < max; i++) sum += value[i]; return (sum / max); } double CalVariane() { mean = CalMean();...