Você está na página 1de 4

End Semester Lab Examination, December-2016

Set D
CSE 1001: Introduction to Computer Programming
Please note that Grading will be strict and without compromise. Hence, you are kindly requested
to go through the instructions thoroughly.

Problem Description
A test was scored out of 100 (only whole marks were given) and 10 students scored the following
marks:
89, 70, 67, 41, 67, 39, 55, 70, 92, 70

You are asked to compute the following statistical measures for the said data set as mentioned
above using user defined methods in Java.

Arithmetic mean (AM)


The arithmetic mean (or simply "mean") of a sample  ,  ,  ,  , . , 
, usually denoted by  , is
the sum of the sampled values divided by the number of items in the sample:


 

Mode
The mode of a set of values is the value that occurs most often.

Median
The median of a set of data values is the middle value of the data set when it has been arranged in
ascending order.

Variance
The variance is defined as the average of the squired differences from the arithmetic mean. We can
define the variance as follows.

1

   
1


Standard Deviation
The standard deviation is a measure that is used to quantify the amount of variation or dispersion of
a set of data values. We can define the standard deviation as follows.

1

   
1


In order to compute the variance and standard deviation the step by step procedure is given as
follows.
1. Compute the arithmetic mean  .
2. Write the table that subtracts the mean from each observed value.
3. Square each of the differences.
4. Add all the differences in this column.
5. Divide by n-1 where n is the number of items in the sample. This is called variance.
6. To get the standard deviation we take the square root of the variance.

PART-A [5 Points]
1. [1 Point] Create an array named as marks of size 10

2. [2 Points] Initialize the array dynamically by entering the data from key board.
89 70

67

41

67

39

55

70

92

70

3. [2 Points] Write a menu driven java program to use this array and invoke the required methods to
compute different statistical measures.
public static void main(String[] args)
{

int choice;
while(true)
{
System.out.println("\n STATISTICS MENU");
System.out.println("*******************");
System.out.println("0:Exit");
System.out.println("1:Compute Arithmetic Mean");
System.out.println("2:Compute Mode");
/* Write remaining menus here */
/* Read the choice */
choice=sc.nextInt();
switch(choice)
{
case 0:
System.exit(0);
case 1:
double am=getArithmeticMean();
System.out.println("Arithmetic Mean="+am);
break;
case 2:

default:
System.out.println("Wrong choice\n");
}
}
}

More over for the above problem you have to edit the java file named as Statistics_Calculator.java.

PART-B [10 Points]


Define the following user defined methods for each of the statistical measure as stated above and
invoke those methods from the main method whenever required. Method headers are provided
below.
4. [2 Points] public static double getArithmeticMean()-This method should return the
arithmetic mean of the data set.
5. [2 Points] public static int getMode()-This method should return the mode of the data
set.
6. [2 Points] public static double getMedian()-This method should return the median of the
data set.
NOTE-1: The Arrays class in Java has a static sort method, which you can invoke with
Arrays.sort(marks).

This method will sort the elements of the array named as marks in

ascending order. In order to use Arrays class in Java, import the package
java.util.Arrays.

7. [2 Points] public static double getVariance()-This method should return the variance of
the data set.
NOTE-2: Please make sure to use getArithmeticMean() inside this method to compute
variance of the said data set. You will not get any points if you dont.
8. [2 Points] public static double getStandardDeviation()-This method should return the
standard deviation of the data set.
NOTE-3: Please make sure to use getVariance() inside this method to compute standard
deviation of the said data set. You will not get any points if you dont.
NOTE-4: In order to find the square root dont use Library Method Math.sqrt().

***************

Você também pode gostar