# Thread: help with sample program

1. Member
Join Date
May 2013
Posts
6
Rep Power
0

## help with sample program

hello ,
I am new member here
I just want you to help me with this assignment plz.

1) Create an array of double of size 20
example
Enter 1st student's grade: 85.88 <enter>
Enter 2nd student's grade: 68.15 <enter>
Enter 3rd student's grade: 75.45 <enter>
...
Enter 20th student's grade: 95.20 <enter>
You are free to choose the grades.

3) Print the average and standard deviation of the grades
for example
average: 68.47
stdev: 19.45

4) Assign letter grades to the students.
top %10 will get A (two people in this case)
next %20 will get B (3rd, 4th, 5th, 6th people will get B)
next %40 will get C (7th, 8th, 9th, 10th, 11th, 12th, 13th, 14th will get C)
next %20 will get D (15th, 16th, 17th, 18th people will get B)
next %10 will get F (19th, 20th people will get B)

1st student's letter grade is A
2nd student's letter is C
....
hope you got the way to calculate the the stdev because I didn't find any way to put it in the first loop of inputting the grades .

2. ## Re: help with sample program

You can calculate the 'ingredients' for the average and standard deviation while reading the individual grades Xi, calculate the sum(Xi) and the sum of the squares sum(Xi^2); when the loop finishes you know 'n', the number of grades entered by the user; so, the average = sum(Xi)/n and the standard deviation = (sum(Xi^2)-sum(Xi)*sum(Xi)/n)/n; (I forgot whether or not to take the square root of this).

kind regards,

Jos

3. Member
Join Date
May 2013
Posts
6
Rep Power
0

## Re: help with sample program

yes but now how I can include the the sigma and then sqrt of the multiplication I'll try more and I'll write the whole code also here OpenStudy

4. ## Re: help with sample program

Originally Posted by mounir
yes but now how I can include the the sigma and then sqrt of the multiplication I'll try more and I'll write the whole code also here OpenStudy
You don't need a 'sigma'; you just have to add the Xi's and the Xi squared in your loop:

Java Code:
```double Xi= 0;
double Xi2= 0;
int n= 0;
double x= <read a number from the user>;
Xi+= X;
Xi2+= X*X;
n++;
}```
kind regards,

Jos

5. Member
Join Date
May 2013
Posts
6
Rep Power
0

## Re: help with sample program

well thank you I figured a way calculate but how to order my array decreasingly with the students and then signing letters to each ?

public static void main(String[] args) throws Exception {
Scanner in=new Scanner (System.in);
System.out.println("input the number of students");
int arr=in.nextInt(); //if in case Students number less than 20
double[] result=new double[arr+1];
int i,j = 0;
double sum=0.0;
double v=0.0;
{

System.out.println("input the grade of Student "+(i+1));
}
double average=sum/arr;
System.out.println("the Average is "+average);
result[0]=100;
{
for( j=0;j<=i;j++){
if(result[j+1]<result[j]){
double temp=result[j];result[j]=result[j+1];result[j+1]=temp;
}
}

}
System.out.println(result[j]);
}
double std =Math.sqrt((1/((double)(arr-1)))*v);
System.out.println("the stdev is "+std);
}

6. Member
Join Date
Aug 2011
Location
Bulgaria
Posts
29
Rep Power
0

## Re: help with sample program

Well, you need to import class java.util.Arrays and use the sort method: Arrays.sort(<your array>). This method will sort the array in its natural order, in the case of numeric values the natural order is ascending(i.e. the array {2, 0 , 1} after the sort will be {0, 1, 2}). Note that in your case the original order of the grades in the array does matter :)

BR,
Kalin

P.S. Of course, if you're interested, you can write your own sort by implementing one of these algorithms:
https://en.wikipedia.org/wiki/Sorting_algorithm
Last edited by kalata; 05-30-2013 at 04:55 PM.

7. Member
Join Date
May 2013
Posts
6
Rep Power
0

## Re: help with sample program

public static void main(String[] args) throws Exception {
Scanner in=new Scanner (System.in);
System.out.println("input the number of students");
int n=in.nextInt(); //if in case Students number less than 20
int[] S=new int[n+1];
int i,j ;
int s=1;
double sum=0.0;
double v=0.0;

{
System.out.println("input the grade of Student "+(i+1));

}
double average=sum/n;
System.out.println("the Average is "+average);
for(s=0;s<=n;s++)
{S[s]=S[s]+1;}
int tem=s=i;
s=s+1;

}
}
}
double std =Math.sqrt((1/((double)(n)))*v);
System.out.println("the stdev is "+std);
}
}

8. Member
Join Date
Jun 2013
Posts
1
Rep Power
0

## Re: help with sample program

I want to suggest you https://www.udemy.com/java-basics-fo...nCode=TECHDIS0. They are providing free java online course. Just join their course and solve your all problems.The course is spread over 128 lectures in 21 sections with practice problems in sections intended to enhance your practical knowledge of concepts learnt throughout the section.

9. Member
Join Date
May 2013
Posts
6
Rep Power
0

## Re: help with sample program

Java Code:
``` public static void main(String[] args) throws Exception {
Scanner in=new Scanner (System.in);
System.out.println("input the number of  students");
int n=in.nextInt();      //if in case Students number less than 20
int[] S=new int[n+1];
int i,j ;
int s=1;
double sum=0.0;
double v=0.0;

{
System.out.println("input the grade of Student "+(i+1));

}
double average=sum/n;
System.out.println("the Average is "+average);
for(s=0;s<=n;s++)
{S[s]=S[s]+1;}
int tem=s=i;
s=s+1;

}
}
}
double std =Math.sqrt((1/((double)(n)))*v);
System.out.println("the stdev is "+std);
}
}```
Last edited by JosAH; 06-04-2013 at 02:08 PM. Reason: added [code] ... [/code] tags

10. Member
Join Date
May 2013
Posts
6
Rep Power
0

## Re: help with sample program

find it ;)
Java Code:
```import java.util.*;
/**
*
* @author smart
*/
public class Count {
/**
* @param args the command line arguments
*/

public static void main(String[] args) throws Exception {
Scanner in=new Scanner (System.in);
System.out.println("input the number of  students");
int n=in.nextInt();      //if in case Students number less than 20
int[] S=new int[n];
int s,i,j;
double average ,v=0.0,sum=0.0;
for(s=0;s<n;s++){S[s]=s;}
{
System.out.println("input the grade of Student "+(i+1));
}
average=sum/n;
for (j=0; j<n-1;j++){
for(i=0 ,s=0;i<n-1;i++,s++){
int tem=S[s];
S[s]=S[s+1];
S[s+1]=tem;
}
}
}
double NA=n/10;  //2 i<2
double NB=n/5;   //4 2<=i<6
double NC=n*2/5; //8 6<=i<14
double NE=n/5;   //4 14<=i<18
double NF=n/10;  //2 18<=i<20
double std =Math.sqrt((1/((double)(n)))*v);
System.out.println("the Average is "+average);
System.out.println("the stdev is "+std);
for(s=0,i=0;(s<n &&i <n);s++,i++){
if(i<NA){
System.out.println("the "+(i+1) + " student which is the "+(S[s]+1)+"th took " +grades[i]+"recieve 'A'");
}
else if (NA<=i && i<NB+NA){
System.out.println("the "+(i+1) + " student which is the "+(S[s]+1)+"th took " +grades[i]+"recieve 'B'");
}
else if (NB+NA<=i && i<NC+NB+NA){
System.out.println("the "+(i+1) + " student which is the "+(S[s]+1)+"th took " +grades[i]+"recieve 'C'");
}
else if (NC+NB+NA<=i && i<NC+NB+NA+NE){
System.out.println("the "+(i+1) + " student which is the "+(S[s]+1)+"th took " +grades[i]+"recieve 'E'");
}
else {
System.out.println("the "+(i+1) + " student which is the "+(S[s]+1)+"th took " +grades[i]+"recieve 'F'");
}
}
}
}```

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•