SlideShare a Scribd company logo
1 of 19
Download to read offline
/*
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, the standard deviation,
the maximum, and the minimum.
*/
public class Stats {
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.
private double max = Double.NEGATIVE_INFINITY; // Largest item seen.
private double min = Double.POSITIVE_INFINITY; // Smallest item seen.
int[] myList;
public int getCount() {
System.out.println(myList.size());
count = myList.size().
// Return number of items that have been entered.
return count;
}
public double getSum() {
int sum = 0;
for (int i = 0; i < myList.length; i++)
{
sum +=mylist[i];
}
return sum;
}
public double getMean() {
int sum = 0;
for (int i = 0; i < myList.length; i++)
{
sum +=mylist[i];
}
if(count > 0)
return sum / count;
else
return -1;
}
public double getMin() {
int smallest = myList[0];
int largetst = myList[0];
for(int i=1; i< mylist.length; i++)
{
if(mylist[i] > largetst)
largetst = numbers[i];
else if (mylist[i] < smallest)
smallest = numbers[i];
}
return smallest;
}
public double getMax() {
int smallest = myList[0];
int largetst = myList[0];
for(int i=1; i< mylist.length; i++)
{
if(mylist[i] > largetst)
largetst = numbers[i];
else if (mylist[i] < smallest)
smallest = numbers[i];
}
return largetst;
}
stats(int [] data)
{
if(data.count <= count)
{
if(myList.size() > 0)
System.arraycopy( myList, 0, data, 0, count );
}
}
stats()
{
Scanner s = new Scanner(System.in);
int count = s.nextInt();
s.nextLine(); // throw away the newline.
int [] numbers = new int[count];
Scanner numScanner = new Scanner(s.nextLine());
for (int i = 0; i < count; i++) {
if (numScanner.hasNextInt()) {
numbers[i] = numScanner.nextInt();
} else {
System.out.println("You didn't provide enough numbers");
break;
}
}
System.arraycopy( myList, 0, numbers, 0, count );
}
stats(int size)
{
setValue(size);
}
private void setValue(int size)
{
count = size;
myList = new int[size];
}
} // end class StatCalc
public class SimpleStats {
public static void main(String[] args) {
Stat calc; // Computes stats for numbers entered by user.
calc = new Stat(100);
int arry[] = {20.20.40,30.80,,70,4,5,6,7,10}
calc.setvalue(array);
double item; // One number entered by the user.
TextIO.putln("Enter your numbers. Enter 0 to end.");
TextIO.putln();
do {
TextIO.put("? ");
item = TextIO.getlnDouble();
if (item != 0)
calc.enter(item);
} while ( item != 0 );
TextIO.putln(" Statistics about your calc: ");
TextIO.putln(" Count: " + calc.getCount());
TextIO.putln(" Sum: " + calc.getSum());
TextIO.putln(" Minimum: " + calc.getMin());
TextIO.putln(" Maximum: " + calc.getMax());
} // end main()
} // end Stats
/*
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, the standard deviation,
the maximum, and the minimum.
*/
public class Stats {
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.
private double max = Double.NEGATIVE_INFINITY; // Largest item seen.
private double min = Double.POSITIVE_INFINITY; // Smallest item seen.
int[] myList;
public int getCount() {
System.out.println(myList.size());
count = myList.size().
// Return number of items that have been entered.
return count;
}
public double getSum() {
int sum = 0;
for (int i = 0; i < myList.length; i++)
{
sum +=mylist[i];
}
return sum;
}
public double getMean() {
int sum = 0;
for (int i = 0; i < myList.length; i++)
{
sum +=mylist[i];
}
if(count > 0)
return sum / count;
else
return -1;
}
public double getMin() {
int smallest = myList[0];
int largetst = myList[0];
for(int i=1; i< mylist.length; i++)
{
if(mylist[i] > largetst)
largetst = numbers[i];
else if (mylist[i] < smallest)
smallest = numbers[i];
}
return smallest;
}
public double getMax() {
int smallest = myList[0];
int largetst = myList[0];
for(int i=1; i< mylist.length; i++)
{
if(mylist[i] > largetst)
largetst = numbers[i];
else if (mylist[i] < smallest)
smallest = numbers[i];
}
return largetst;
}
stats(int [] data)
{
if(data.count <= count)
{
if(myList.size() > 0)
System.arraycopy( myList, 0, data, 0, count );
}
}
stats()
{
Scanner s = new Scanner(System.in);
int count = s.nextInt();
s.nextLine(); // throw away the newline.
int [] numbers = new int[count];
Scanner numScanner = new Scanner(s.nextLine());
for (int i = 0; i < count; i++) {
if (numScanner.hasNextInt()) {
numbers[i] = numScanner.nextInt();
} else {
System.out.println("You didn't provide enough numbers");
break;
}
}
System.arraycopy( myList, 0, numbers, 0, count );
}
stats(int size)
{
setValue(size);
}
private void setValue(int size)
{
count = size;
myList = new int[size];
}
} // end class StatCalc
public class SimpleStats {
public static void main(String[] args) {
Stat calc; // Computes stats for numbers entered by user.
calc = new Stat(100);
int arry[] = {20.20.40,30.80,,70,4,5,6,7,10}
calc.setvalue(array);
double item; // One number entered by the user.
TextIO.putln("Enter your numbers. Enter 0 to end.");
TextIO.putln();
do {
TextIO.put("? ");
item = TextIO.getlnDouble();
if (item != 0)
calc.enter(item);
} while ( item != 0 );
TextIO.putln(" Statistics about your calc: ");
TextIO.putln(" Count: " + calc.getCount());
TextIO.putln(" Sum: " + calc.getSum());
TextIO.putln(" Minimum: " + calc.getMin());
TextIO.putln(" Maximum: " + calc.getMax());
} // end main()
} // end Stats
Solution
/*
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, the standard deviation,
the maximum, and the minimum.
*/
public class Stats {
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.
private double max = Double.NEGATIVE_INFINITY; // Largest item seen.
private double min = Double.POSITIVE_INFINITY; // Smallest item seen.
int[] myList;
public int getCount() {
System.out.println(myList.size());
count = myList.size().
// Return number of items that have been entered.
return count;
}
public double getSum() {
int sum = 0;
for (int i = 0; i < myList.length; i++)
{
sum +=mylist[i];
}
return sum;
}
public double getMean() {
int sum = 0;
for (int i = 0; i < myList.length; i++)
{
sum +=mylist[i];
}
if(count > 0)
return sum / count;
else
return -1;
}
public double getMin() {
int smallest = myList[0];
int largetst = myList[0];
for(int i=1; i< mylist.length; i++)
{
if(mylist[i] > largetst)
largetst = numbers[i];
else if (mylist[i] < smallest)
smallest = numbers[i];
}
return smallest;
}
public double getMax() {
int smallest = myList[0];
int largetst = myList[0];
for(int i=1; i< mylist.length; i++)
{
if(mylist[i] > largetst)
largetst = numbers[i];
else if (mylist[i] < smallest)
smallest = numbers[i];
}
return largetst;
}
stats(int [] data)
{
if(data.count <= count)
{
if(myList.size() > 0)
System.arraycopy( myList, 0, data, 0, count );
}
}
stats()
{
Scanner s = new Scanner(System.in);
int count = s.nextInt();
s.nextLine(); // throw away the newline.
int [] numbers = new int[count];
Scanner numScanner = new Scanner(s.nextLine());
for (int i = 0; i < count; i++) {
if (numScanner.hasNextInt()) {
numbers[i] = numScanner.nextInt();
} else {
System.out.println("You didn't provide enough numbers");
break;
}
}
System.arraycopy( myList, 0, numbers, 0, count );
}
stats(int size)
{
setValue(size);
}
private void setValue(int size)
{
count = size;
myList = new int[size];
}
} // end class StatCalc
public class SimpleStats {
public static void main(String[] args) {
Stat calc; // Computes stats for numbers entered by user.
calc = new Stat(100);
int arry[] = {20.20.40,30.80,,70,4,5,6,7,10}
calc.setvalue(array);
double item; // One number entered by the user.
TextIO.putln("Enter your numbers. Enter 0 to end.");
TextIO.putln();
do {
TextIO.put("? ");
item = TextIO.getlnDouble();
if (item != 0)
calc.enter(item);
} while ( item != 0 );
TextIO.putln(" Statistics about your calc: ");
TextIO.putln(" Count: " + calc.getCount());
TextIO.putln(" Sum: " + calc.getSum());
TextIO.putln(" Minimum: " + calc.getMin());
TextIO.putln(" Maximum: " + calc.getMax());
} // end main()
} // end Stats
/*
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, the standard deviation,
the maximum, and the minimum.
*/
public class Stats {
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.
private double max = Double.NEGATIVE_INFINITY; // Largest item seen.
private double min = Double.POSITIVE_INFINITY; // Smallest item seen.
int[] myList;
public int getCount() {
System.out.println(myList.size());
count = myList.size().
// Return number of items that have been entered.
return count;
}
public double getSum() {
int sum = 0;
for (int i = 0; i < myList.length; i++)
{
sum +=mylist[i];
}
return sum;
}
public double getMean() {
int sum = 0;
for (int i = 0; i < myList.length; i++)
{
sum +=mylist[i];
}
if(count > 0)
return sum / count;
else
return -1;
}
public double getMin() {
int smallest = myList[0];
int largetst = myList[0];
for(int i=1; i< mylist.length; i++)
{
if(mylist[i] > largetst)
largetst = numbers[i];
else if (mylist[i] < smallest)
smallest = numbers[i];
}
return smallest;
}
public double getMax() {
int smallest = myList[0];
int largetst = myList[0];
for(int i=1; i< mylist.length; i++)
{
if(mylist[i] > largetst)
largetst = numbers[i];
else if (mylist[i] < smallest)
smallest = numbers[i];
}
return largetst;
}
stats(int [] data)
{
if(data.count <= count)
{
if(myList.size() > 0)
System.arraycopy( myList, 0, data, 0, count );
}
}
stats()
{
Scanner s = new Scanner(System.in);
int count = s.nextInt();
s.nextLine(); // throw away the newline.
int [] numbers = new int[count];
Scanner numScanner = new Scanner(s.nextLine());
for (int i = 0; i < count; i++) {
if (numScanner.hasNextInt()) {
numbers[i] = numScanner.nextInt();
} else {
System.out.println("You didn't provide enough numbers");
break;
}
}
System.arraycopy( myList, 0, numbers, 0, count );
}
stats(int size)
{
setValue(size);
}
private void setValue(int size)
{
count = size;
myList = new int[size];
}
} // end class StatCalc
public class SimpleStats {
public static void main(String[] args) {
Stat calc; // Computes stats for numbers entered by user.
calc = new Stat(100);
int arry[] = {20.20.40,30.80,,70,4,5,6,7,10}
calc.setvalue(array);
double item; // One number entered by the user.
TextIO.putln("Enter your numbers. Enter 0 to end.");
TextIO.putln();
do {
TextIO.put("? ");
item = TextIO.getlnDouble();
if (item != 0)
calc.enter(item);
} while ( item != 0 );
TextIO.putln(" Statistics about your calc: ");
TextIO.putln(" Count: " + calc.getCount());
TextIO.putln(" Sum: " + calc.getSum());
TextIO.putln(" Minimum: " + calc.getMin());
TextIO.putln(" Maximum: " + calc.getMax());
} // end main()
} // end Stats

More Related Content

Similar to An object of class StatCalc can be used to compute several simp.pdf

Digits.javapackage week04;import java.util.Scanner; public cla.pdf
Digits.javapackage week04;import java.util.Scanner; public cla.pdfDigits.javapackage week04;import java.util.Scanner; public cla.pdf
Digits.javapackage week04;import java.util.Scanner; public cla.pdfannapurnnatextailes
 
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdfArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdfdeepua8
 
Java căn bản - Chapter10
Java căn bản - Chapter10Java căn bản - Chapter10
Java căn bản - Chapter10Vince Vo
 
I am stuck on parts E and FExercise 1      NumberListTester.java.pdf
I am stuck on parts E and FExercise 1      NumberListTester.java.pdfI am stuck on parts E and FExercise 1      NumberListTester.java.pdf
I am stuck on parts E and FExercise 1      NumberListTester.java.pdfRAJATCHUGH12
 
Chapter 7.1
Chapter 7.1Chapter 7.1
Chapter 7.1sotlsoc
 
Write a program that will test a name) method no sorting routine from.docx
 Write a program that will test a name) method no sorting routine from.docx Write a program that will test a name) method no sorting routine from.docx
Write a program that will test a name) method no sorting routine from.docxajoy21
 
import java.util.Scanner;public class ArrayOperation {    inp.pdf
import java.util.Scanner;public class ArrayOperation {     inp.pdfimport java.util.Scanner;public class ArrayOperation {     inp.pdf
import java.util.Scanner;public class ArrayOperation {    inp.pdfangelsfashion1
 
public class TrequeT extends AbstractListT { .pdf
  public class TrequeT extends AbstractListT {  .pdf  public class TrequeT extends AbstractListT {  .pdf
public class TrequeT extends AbstractListT { .pdfinfo30292
 
Create a menu-driven program that will accept a collection of non-ne.pdf
Create a menu-driven program that will accept a collection of non-ne.pdfCreate a menu-driven program that will accept a collection of non-ne.pdf
Create a menu-driven program that will accept a collection of non-ne.pdfrajeshjangid1865
 
program#include iostreamusing namespace std;void calculatio.pdf
program#include iostreamusing namespace std;void calculatio.pdfprogram#include iostreamusing namespace std;void calculatio.pdf
program#include iostreamusing namespace std;void calculatio.pdfinfo382133
 
when I compile to get the survey title the overload constructor asks.docx
when I compile to get the survey title the overload constructor asks.docxwhen I compile to get the survey title the overload constructor asks.docx
when I compile to get the survey title the overload constructor asks.docxlashandaotley
 
Hello. I need help fixing this Java Code on Eclipse. Please fix part.pdf
Hello. I need help fixing this Java Code on Eclipse. Please fix part.pdfHello. I need help fixing this Java Code on Eclipse. Please fix part.pdf
Hello. I need help fixing this Java Code on Eclipse. Please fix part.pdfflashfashioncasualwe
 
import java.util.ArrayList;public class Checkout{private.docx
import java.util.ArrayList;public class Checkout{private.docximport java.util.ArrayList;public class Checkout{private.docx
import java.util.ArrayList;public class Checkout{private.docxAbhinav816839
 
Oops lab manual2
Oops lab manual2Oops lab manual2
Oops lab manual2Mouna Guru
 
OOP program questions with answers
OOP program questions with answersOOP program questions with answers
OOP program questions with answersQuratulain Naqvi
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfravikapoorindia
 
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdfJAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdfarpaqindia
 
a) Write the recursive function in C++ to sort a set of data using M.pdf
a) Write the recursive function in C++ to sort a set of data using M.pdfa) Write the recursive function in C++ to sort a set of data using M.pdf
a) Write the recursive function in C++ to sort a set of data using M.pdfnageswara1958
 

Similar to An object of class StatCalc can be used to compute several simp.pdf (20)

Digits.javapackage week04;import java.util.Scanner; public cla.pdf
Digits.javapackage week04;import java.util.Scanner; public cla.pdfDigits.javapackage week04;import java.util.Scanner; public cla.pdf
Digits.javapackage week04;import java.util.Scanner; public cla.pdf
 
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdfArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
 
Statistics.cpp
Statistics.cppStatistics.cpp
Statistics.cpp
 
Java căn bản - Chapter10
Java căn bản - Chapter10Java căn bản - Chapter10
Java căn bản - Chapter10
 
I am stuck on parts E and FExercise 1      NumberListTester.java.pdf
I am stuck on parts E and FExercise 1      NumberListTester.java.pdfI am stuck on parts E and FExercise 1      NumberListTester.java.pdf
I am stuck on parts E and FExercise 1      NumberListTester.java.pdf
 
Chapter 7.1
Chapter 7.1Chapter 7.1
Chapter 7.1
 
Write a program that will test a name) method no sorting routine from.docx
 Write a program that will test a name) method no sorting routine from.docx Write a program that will test a name) method no sorting routine from.docx
Write a program that will test a name) method no sorting routine from.docx
 
import java.util.Scanner;public class ArrayOperation {    inp.pdf
import java.util.Scanner;public class ArrayOperation {     inp.pdfimport java.util.Scanner;public class ArrayOperation {     inp.pdf
import java.util.Scanner;public class ArrayOperation {    inp.pdf
 
public class TrequeT extends AbstractListT { .pdf
  public class TrequeT extends AbstractListT {  .pdf  public class TrequeT extends AbstractListT {  .pdf
public class TrequeT extends AbstractListT { .pdf
 
Create a menu-driven program that will accept a collection of non-ne.pdf
Create a menu-driven program that will accept a collection of non-ne.pdfCreate a menu-driven program that will accept a collection of non-ne.pdf
Create a menu-driven program that will accept a collection of non-ne.pdf
 
program#include iostreamusing namespace std;void calculatio.pdf
program#include iostreamusing namespace std;void calculatio.pdfprogram#include iostreamusing namespace std;void calculatio.pdf
program#include iostreamusing namespace std;void calculatio.pdf
 
when I compile to get the survey title the overload constructor asks.docx
when I compile to get the survey title the overload constructor asks.docxwhen I compile to get the survey title the overload constructor asks.docx
when I compile to get the survey title the overload constructor asks.docx
 
Hello. I need help fixing this Java Code on Eclipse. Please fix part.pdf
Hello. I need help fixing this Java Code on Eclipse. Please fix part.pdfHello. I need help fixing this Java Code on Eclipse. Please fix part.pdf
Hello. I need help fixing this Java Code on Eclipse. Please fix part.pdf
 
import java.util.ArrayList;public class Checkout{private.docx
import java.util.ArrayList;public class Checkout{private.docximport java.util.ArrayList;public class Checkout{private.docx
import java.util.ArrayList;public class Checkout{private.docx
 
6_Array.pptx
6_Array.pptx6_Array.pptx
6_Array.pptx
 
Oops lab manual2
Oops lab manual2Oops lab manual2
Oops lab manual2
 
OOP program questions with answers
OOP program questions with answersOOP program questions with answers
OOP program questions with answers
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdf
 
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdfJAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
 
a) Write the recursive function in C++ to sort a set of data using M.pdf
a) Write the recursive function in C++ to sort a set of data using M.pdfa) Write the recursive function in C++ to sort a set of data using M.pdf
a) Write the recursive function in C++ to sort a set of data using M.pdf
 

More from aravlitraders2012

Exception to indicate that Singly LinkedList is empty. .pdf
  Exception to indicate that Singly LinkedList is empty. .pdf  Exception to indicate that Singly LinkedList is empty. .pdf
Exception to indicate that Singly LinkedList is empty. .pdfaravlitraders2012
 
Electronegativity - Electronegativity is an atom.pdf
                     Electronegativity - Electronegativity is an atom.pdf                     Electronegativity - Electronegativity is an atom.pdf
Electronegativity - Electronegativity is an atom.pdfaravlitraders2012
 
Sequence.h#ifndef MAIN #define MAIN #include cstdlibclass .pdf
Sequence.h#ifndef MAIN #define MAIN #include cstdlibclass .pdfSequence.h#ifndef MAIN #define MAIN #include cstdlibclass .pdf
Sequence.h#ifndef MAIN #define MAIN #include cstdlibclass .pdfaravlitraders2012
 
In the 1st Question, As the polymorphisms occur in the non-coding se.pdf
  In the 1st Question, As the polymorphisms occur in the non-coding se.pdf  In the 1st Question, As the polymorphisms occur in the non-coding se.pdf
In the 1st Question, As the polymorphisms occur in the non-coding se.pdfaravlitraders2012
 
I noticed that temperature is not mentioned. A) .pdf
                     I noticed that temperature is not mentioned.  A) .pdf                     I noticed that temperature is not mentioned.  A) .pdf
I noticed that temperature is not mentioned. A) .pdfaravlitraders2012
 
1. Briefly describe the structured design approach and the object-or.pdf
1. Briefly describe the structured design approach and the object-or.pdf1. Briefly describe the structured design approach and the object-or.pdf
1. Briefly describe the structured design approach and the object-or.pdfaravlitraders2012
 
1) Protocols are needed so your computer can interact with other com.pdf
1) Protocols are needed so your computer can interact with other com.pdf1) Protocols are needed so your computer can interact with other com.pdf
1) Protocols are needed so your computer can interact with other com.pdfaravlitraders2012
 
argon is inert gas , doesnot chemically reacts wi.pdf
                     argon is inert gas , doesnot chemically reacts wi.pdf                     argon is inert gas , doesnot chemically reacts wi.pdf
argon is inert gas , doesnot chemically reacts wi.pdfaravlitraders2012
 
#include sstream #include linkylist.h #include iostream.pdf
#include sstream #include linkylist.h #include iostream.pdf#include sstream #include linkylist.h #include iostream.pdf
#include sstream #include linkylist.h #include iostream.pdfaravlitraders2012
 
Function header If a program contain a function definition, that .pdf
Function header If a program contain a function definition, that .pdfFunction header If a program contain a function definition, that .pdf
Function header If a program contain a function definition, that .pdfaravlitraders2012
 
GameOfLife.cs using System; using System.Collections.Generic;.pdf
GameOfLife.cs using System; using System.Collections.Generic;.pdfGameOfLife.cs using System; using System.Collections.Generic;.pdf
GameOfLife.cs using System; using System.Collections.Generic;.pdfaravlitraders2012
 
With the vast increase in technology, the number of ways that the us.pdf
With the vast increase in technology, the number of ways that the us.pdfWith the vast increase in technology, the number of ways that the us.pdf
With the vast increase in technology, the number of ways that the us.pdfaravlitraders2012
 
Let n = size of the hash table hashTable = array of size n, w.pdf
Let n = size of the hash table  hashTable = array of size n, w.pdfLet n = size of the hash table  hashTable = array of size n, w.pdf
Let n = size of the hash table hashTable = array of size n, w.pdfaravlitraders2012
 
What is the need of the t Distribution According to the central.pdf
What is the need of the t Distribution According to the central.pdfWhat is the need of the t Distribution According to the central.pdf
What is the need of the t Distribution According to the central.pdfaravlitraders2012
 
We can see in course of evolution of plant there was a transition fr.pdf
We can see in course of evolution of plant there was a transition fr.pdfWe can see in course of evolution of plant there was a transition fr.pdf
We can see in course of evolution of plant there was a transition fr.pdfaravlitraders2012
 
Wave CharacterMany of the things that light does are only expla.pdf
 Wave CharacterMany of the things that light does are only expla.pdf Wave CharacterMany of the things that light does are only expla.pdf
Wave CharacterMany of the things that light does are only expla.pdfaravlitraders2012
 
The solvent doesnt interfere with the purification processOil Bath.pdf
The solvent doesnt interfere with the purification processOil Bath.pdfThe solvent doesnt interfere with the purification processOil Bath.pdf
The solvent doesnt interfere with the purification processOil Bath.pdfaravlitraders2012
 
The answers can be found below as discussedPart 1)The human gen.pdf
The answers can be found below as discussedPart 1)The human gen.pdfThe answers can be found below as discussedPart 1)The human gen.pdf
The answers can be found below as discussedPart 1)The human gen.pdfaravlitraders2012
 
Solution (3)The smallest respiratory bronchioles subdivide into t.pdf
Solution (3)The smallest respiratory bronchioles subdivide into t.pdfSolution (3)The smallest respiratory bronchioles subdivide into t.pdf
Solution (3)The smallest respiratory bronchioles subdivide into t.pdfaravlitraders2012
 
An asset manager of a hedge fund or a mutual funds is the one who di.pdf
An asset manager of a hedge fund or a mutual funds is the one who di.pdfAn asset manager of a hedge fund or a mutual funds is the one who di.pdf
An asset manager of a hedge fund or a mutual funds is the one who di.pdfaravlitraders2012
 

More from aravlitraders2012 (20)

Exception to indicate that Singly LinkedList is empty. .pdf
  Exception to indicate that Singly LinkedList is empty. .pdf  Exception to indicate that Singly LinkedList is empty. .pdf
Exception to indicate that Singly LinkedList is empty. .pdf
 
Electronegativity - Electronegativity is an atom.pdf
                     Electronegativity - Electronegativity is an atom.pdf                     Electronegativity - Electronegativity is an atom.pdf
Electronegativity - Electronegativity is an atom.pdf
 
Sequence.h#ifndef MAIN #define MAIN #include cstdlibclass .pdf
Sequence.h#ifndef MAIN #define MAIN #include cstdlibclass .pdfSequence.h#ifndef MAIN #define MAIN #include cstdlibclass .pdf
Sequence.h#ifndef MAIN #define MAIN #include cstdlibclass .pdf
 
In the 1st Question, As the polymorphisms occur in the non-coding se.pdf
  In the 1st Question, As the polymorphisms occur in the non-coding se.pdf  In the 1st Question, As the polymorphisms occur in the non-coding se.pdf
In the 1st Question, As the polymorphisms occur in the non-coding se.pdf
 
I noticed that temperature is not mentioned. A) .pdf
                     I noticed that temperature is not mentioned.  A) .pdf                     I noticed that temperature is not mentioned.  A) .pdf
I noticed that temperature is not mentioned. A) .pdf
 
1. Briefly describe the structured design approach and the object-or.pdf
1. Briefly describe the structured design approach and the object-or.pdf1. Briefly describe the structured design approach and the object-or.pdf
1. Briefly describe the structured design approach and the object-or.pdf
 
1) Protocols are needed so your computer can interact with other com.pdf
1) Protocols are needed so your computer can interact with other com.pdf1) Protocols are needed so your computer can interact with other com.pdf
1) Protocols are needed so your computer can interact with other com.pdf
 
argon is inert gas , doesnot chemically reacts wi.pdf
                     argon is inert gas , doesnot chemically reacts wi.pdf                     argon is inert gas , doesnot chemically reacts wi.pdf
argon is inert gas , doesnot chemically reacts wi.pdf
 
#include sstream #include linkylist.h #include iostream.pdf
#include sstream #include linkylist.h #include iostream.pdf#include sstream #include linkylist.h #include iostream.pdf
#include sstream #include linkylist.h #include iostream.pdf
 
Function header If a program contain a function definition, that .pdf
Function header If a program contain a function definition, that .pdfFunction header If a program contain a function definition, that .pdf
Function header If a program contain a function definition, that .pdf
 
GameOfLife.cs using System; using System.Collections.Generic;.pdf
GameOfLife.cs using System; using System.Collections.Generic;.pdfGameOfLife.cs using System; using System.Collections.Generic;.pdf
GameOfLife.cs using System; using System.Collections.Generic;.pdf
 
With the vast increase in technology, the number of ways that the us.pdf
With the vast increase in technology, the number of ways that the us.pdfWith the vast increase in technology, the number of ways that the us.pdf
With the vast increase in technology, the number of ways that the us.pdf
 
Let n = size of the hash table hashTable = array of size n, w.pdf
Let n = size of the hash table  hashTable = array of size n, w.pdfLet n = size of the hash table  hashTable = array of size n, w.pdf
Let n = size of the hash table hashTable = array of size n, w.pdf
 
What is the need of the t Distribution According to the central.pdf
What is the need of the t Distribution According to the central.pdfWhat is the need of the t Distribution According to the central.pdf
What is the need of the t Distribution According to the central.pdf
 
We can see in course of evolution of plant there was a transition fr.pdf
We can see in course of evolution of plant there was a transition fr.pdfWe can see in course of evolution of plant there was a transition fr.pdf
We can see in course of evolution of plant there was a transition fr.pdf
 
Wave CharacterMany of the things that light does are only expla.pdf
 Wave CharacterMany of the things that light does are only expla.pdf Wave CharacterMany of the things that light does are only expla.pdf
Wave CharacterMany of the things that light does are only expla.pdf
 
The solvent doesnt interfere with the purification processOil Bath.pdf
The solvent doesnt interfere with the purification processOil Bath.pdfThe solvent doesnt interfere with the purification processOil Bath.pdf
The solvent doesnt interfere with the purification processOil Bath.pdf
 
The answers can be found below as discussedPart 1)The human gen.pdf
The answers can be found below as discussedPart 1)The human gen.pdfThe answers can be found below as discussedPart 1)The human gen.pdf
The answers can be found below as discussedPart 1)The human gen.pdf
 
Solution (3)The smallest respiratory bronchioles subdivide into t.pdf
Solution (3)The smallest respiratory bronchioles subdivide into t.pdfSolution (3)The smallest respiratory bronchioles subdivide into t.pdf
Solution (3)The smallest respiratory bronchioles subdivide into t.pdf
 
An asset manager of a hedge fund or a mutual funds is the one who di.pdf
An asset manager of a hedge fund or a mutual funds is the one who di.pdfAn asset manager of a hedge fund or a mutual funds is the one who di.pdf
An asset manager of a hedge fund or a mutual funds is the one who di.pdf
 

Recently uploaded

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 

Recently uploaded (20)

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 

An object of class StatCalc can be used to compute several simp.pdf

  • 1. /* 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, the standard deviation, the maximum, and the minimum. */ public class Stats { 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. private double max = Double.NEGATIVE_INFINITY; // Largest item seen. private double min = Double.POSITIVE_INFINITY; // Smallest item seen. int[] myList; public int getCount() { System.out.println(myList.size()); count = myList.size(). // Return number of items that have been entered. return count; } public double getSum() { int sum = 0; for (int i = 0; i < myList.length; i++) { sum +=mylist[i]; }
  • 2. return sum; } public double getMean() { int sum = 0; for (int i = 0; i < myList.length; i++) { sum +=mylist[i]; } if(count > 0) return sum / count; else return -1; } public double getMin() { int smallest = myList[0]; int largetst = myList[0]; for(int i=1; i< mylist.length; i++) { if(mylist[i] > largetst) largetst = numbers[i]; else if (mylist[i] < smallest) smallest = numbers[i]; } return smallest; } public double getMax() { int smallest = myList[0];
  • 3. int largetst = myList[0]; for(int i=1; i< mylist.length; i++) { if(mylist[i] > largetst) largetst = numbers[i]; else if (mylist[i] < smallest) smallest = numbers[i]; } return largetst; } stats(int [] data) { if(data.count <= count) { if(myList.size() > 0) System.arraycopy( myList, 0, data, 0, count ); } } stats() { Scanner s = new Scanner(System.in); int count = s.nextInt(); s.nextLine(); // throw away the newline. int [] numbers = new int[count]; Scanner numScanner = new Scanner(s.nextLine()); for (int i = 0; i < count; i++) { if (numScanner.hasNextInt()) {
  • 4. numbers[i] = numScanner.nextInt(); } else { System.out.println("You didn't provide enough numbers"); break; } } System.arraycopy( myList, 0, numbers, 0, count ); } stats(int size) { setValue(size); } private void setValue(int size) { count = size; myList = new int[size]; } } // end class StatCalc public class SimpleStats { public static void main(String[] args) { Stat calc; // Computes stats for numbers entered by user. calc = new Stat(100); int arry[] = {20.20.40,30.80,,70,4,5,6,7,10} calc.setvalue(array);
  • 5. double item; // One number entered by the user. TextIO.putln("Enter your numbers. Enter 0 to end."); TextIO.putln(); do { TextIO.put("? "); item = TextIO.getlnDouble(); if (item != 0) calc.enter(item); } while ( item != 0 ); TextIO.putln(" Statistics about your calc: "); TextIO.putln(" Count: " + calc.getCount()); TextIO.putln(" Sum: " + calc.getSum()); TextIO.putln(" Minimum: " + calc.getMin()); TextIO.putln(" Maximum: " + calc.getMax()); } // end main() } // end Stats /* 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, the standard deviation, the maximum, and the minimum. */ public class Stats { private int count; // Number of numbers that have been entered. private double sum; // The sum of all the items that have been entered.
  • 6. private double squareSum; // The sum of the squares of all the items. private double max = Double.NEGATIVE_INFINITY; // Largest item seen. private double min = Double.POSITIVE_INFINITY; // Smallest item seen. int[] myList; public int getCount() { System.out.println(myList.size()); count = myList.size(). // Return number of items that have been entered. return count; } public double getSum() { int sum = 0; for (int i = 0; i < myList.length; i++) { sum +=mylist[i]; } return sum; } public double getMean() { int sum = 0; for (int i = 0; i < myList.length; i++) { sum +=mylist[i]; } if(count > 0) return sum / count; else
  • 7. return -1; } public double getMin() { int smallest = myList[0]; int largetst = myList[0]; for(int i=1; i< mylist.length; i++) { if(mylist[i] > largetst) largetst = numbers[i]; else if (mylist[i] < smallest) smallest = numbers[i]; } return smallest; } public double getMax() { int smallest = myList[0]; int largetst = myList[0]; for(int i=1; i< mylist.length; i++) { if(mylist[i] > largetst) largetst = numbers[i]; else if (mylist[i] < smallest) smallest = numbers[i]; } return largetst; }
  • 8. stats(int [] data) { if(data.count <= count) { if(myList.size() > 0) System.arraycopy( myList, 0, data, 0, count ); } } stats() { Scanner s = new Scanner(System.in); int count = s.nextInt(); s.nextLine(); // throw away the newline. int [] numbers = new int[count]; Scanner numScanner = new Scanner(s.nextLine()); for (int i = 0; i < count; i++) { if (numScanner.hasNextInt()) { numbers[i] = numScanner.nextInt(); } else { System.out.println("You didn't provide enough numbers"); break; } } System.arraycopy( myList, 0, numbers, 0, count ); } stats(int size) {
  • 9. setValue(size); } private void setValue(int size) { count = size; myList = new int[size]; } } // end class StatCalc public class SimpleStats { public static void main(String[] args) { Stat calc; // Computes stats for numbers entered by user. calc = new Stat(100); int arry[] = {20.20.40,30.80,,70,4,5,6,7,10} calc.setvalue(array); double item; // One number entered by the user. TextIO.putln("Enter your numbers. Enter 0 to end."); TextIO.putln(); do { TextIO.put("? "); item = TextIO.getlnDouble(); if (item != 0) calc.enter(item); } while ( item != 0 ); TextIO.putln(" Statistics about your calc: ");
  • 10. TextIO.putln(" Count: " + calc.getCount()); TextIO.putln(" Sum: " + calc.getSum()); TextIO.putln(" Minimum: " + calc.getMin()); TextIO.putln(" Maximum: " + calc.getMax()); } // end main() } // end Stats Solution /* 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, the standard deviation, the maximum, and the minimum. */ public class Stats { 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. private double max = Double.NEGATIVE_INFINITY; // Largest item seen. private double min = Double.POSITIVE_INFINITY; // Smallest item seen. int[] myList; public int getCount() { System.out.println(myList.size());
  • 11. count = myList.size(). // Return number of items that have been entered. return count; } public double getSum() { int sum = 0; for (int i = 0; i < myList.length; i++) { sum +=mylist[i]; } return sum; } public double getMean() { int sum = 0; for (int i = 0; i < myList.length; i++) { sum +=mylist[i]; } if(count > 0) return sum / count; else return -1; } public double getMin() { int smallest = myList[0]; int largetst = myList[0]; for(int i=1; i< mylist.length; i++)
  • 12. { if(mylist[i] > largetst) largetst = numbers[i]; else if (mylist[i] < smallest) smallest = numbers[i]; } return smallest; } public double getMax() { int smallest = myList[0]; int largetst = myList[0]; for(int i=1; i< mylist.length; i++) { if(mylist[i] > largetst) largetst = numbers[i]; else if (mylist[i] < smallest) smallest = numbers[i]; } return largetst; } stats(int [] data) { if(data.count <= count) { if(myList.size() > 0) System.arraycopy( myList, 0, data, 0, count ); }
  • 13. } stats() { Scanner s = new Scanner(System.in); int count = s.nextInt(); s.nextLine(); // throw away the newline. int [] numbers = new int[count]; Scanner numScanner = new Scanner(s.nextLine()); for (int i = 0; i < count; i++) { if (numScanner.hasNextInt()) { numbers[i] = numScanner.nextInt(); } else { System.out.println("You didn't provide enough numbers"); break; } } System.arraycopy( myList, 0, numbers, 0, count ); } stats(int size) { setValue(size); } private void setValue(int size) { count = size; myList = new int[size]; }
  • 14. } // end class StatCalc public class SimpleStats { public static void main(String[] args) { Stat calc; // Computes stats for numbers entered by user. calc = new Stat(100); int arry[] = {20.20.40,30.80,,70,4,5,6,7,10} calc.setvalue(array); double item; // One number entered by the user. TextIO.putln("Enter your numbers. Enter 0 to end."); TextIO.putln(); do { TextIO.put("? "); item = TextIO.getlnDouble(); if (item != 0) calc.enter(item); } while ( item != 0 ); TextIO.putln(" Statistics about your calc: "); TextIO.putln(" Count: " + calc.getCount()); TextIO.putln(" Sum: " + calc.getSum()); TextIO.putln(" Minimum: " + calc.getMin()); TextIO.putln(" Maximum: " + calc.getMax()); } // end main() } // end Stats
  • 15. /* 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, the standard deviation, the maximum, and the minimum. */ public class Stats { 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. private double max = Double.NEGATIVE_INFINITY; // Largest item seen. private double min = Double.POSITIVE_INFINITY; // Smallest item seen. int[] myList; public int getCount() { System.out.println(myList.size()); count = myList.size(). // Return number of items that have been entered. return count; } public double getSum() { int sum = 0; for (int i = 0; i < myList.length; i++) { sum +=mylist[i]; }
  • 16. return sum; } public double getMean() { int sum = 0; for (int i = 0; i < myList.length; i++) { sum +=mylist[i]; } if(count > 0) return sum / count; else return -1; } public double getMin() { int smallest = myList[0]; int largetst = myList[0]; for(int i=1; i< mylist.length; i++) { if(mylist[i] > largetst) largetst = numbers[i]; else if (mylist[i] < smallest) smallest = numbers[i]; } return smallest; } public double getMax() { int smallest = myList[0]; int largetst = myList[0];
  • 17. for(int i=1; i< mylist.length; i++) { if(mylist[i] > largetst) largetst = numbers[i]; else if (mylist[i] < smallest) smallest = numbers[i]; } return largetst; } stats(int [] data) { if(data.count <= count) { if(myList.size() > 0) System.arraycopy( myList, 0, data, 0, count ); } } stats() { Scanner s = new Scanner(System.in); int count = s.nextInt(); s.nextLine(); // throw away the newline. int [] numbers = new int[count]; Scanner numScanner = new Scanner(s.nextLine()); for (int i = 0; i < count; i++) { if (numScanner.hasNextInt()) { numbers[i] = numScanner.nextInt();
  • 18. } else { System.out.println("You didn't provide enough numbers"); break; } } System.arraycopy( myList, 0, numbers, 0, count ); } stats(int size) { setValue(size); } private void setValue(int size) { count = size; myList = new int[size]; } } // end class StatCalc public class SimpleStats { public static void main(String[] args) { Stat calc; // Computes stats for numbers entered by user. calc = new Stat(100); int arry[] = {20.20.40,30.80,,70,4,5,6,7,10} calc.setvalue(array);
  • 19. double item; // One number entered by the user. TextIO.putln("Enter your numbers. Enter 0 to end."); TextIO.putln(); do { TextIO.put("? "); item = TextIO.getlnDouble(); if (item != 0) calc.enter(item); } while ( item != 0 ); TextIO.putln(" Statistics about your calc: "); TextIO.putln(" Count: " + calc.getCount()); TextIO.putln(" Sum: " + calc.getSum()); TextIO.putln(" Minimum: " + calc.getMin()); TextIO.putln(" Maximum: " + calc.getMax()); } // end main() } // end Stats