Results 1 to 10 of 10
Thread: help with sample program
 05292013, 11:50 AM #1Member
 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.
Statistical Analysis of student grades.
1) Create an array of double of size 20
2) Ask user to enter 20 grades
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)
5) print the letter grades
1st student's letter grade is A
2nd student's letter is C
3rd student's letter grade B
....
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 .
 05292013, 12:50 PM #2
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,775
 Blog Entries
 7
 Rep Power
 21
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,
Joscenosillicaphobia: the fear for an empty beer glass
 05292013, 03:54 PM #3Member
 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
 05292013, 07:18 PM #4
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,775
 Blog Entries
 7
 Rep Power
 21
Re: help with sample program
cenosillicaphobia: the fear for an empty beer glass
 05302013, 12:42 PM #5Member
 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[] grades=new double [arr];
double[] result=new double[arr+1];
int i,j = 0;
double sum=0.0;
double v=0.0;
for( i=0;i<grades.length;i++)
{
System.out.println("input the grade of Student "+(i+1));
grades[i]=in.nextDouble();
sum=sum+grades[i];
}
double average=sum/arr;
System.out.println("the Average is "+average);
result[0]=100;
for ( i=0; i<grades.length;i++)
{
if(grades[i]<result[0]){
for( j=0;j<=i;j++){
result[j]=grades[i];
if(result[j+1]<result[j]){
double temp=result[j];result[j]=result[j+1];result[j+1]=temp;
}
}
}
v =v+(grades[i]  average) * (grades[i]  average);
System.out.println(result[j]);
System.out.println(grades[i]);
}
double std =Math.sqrt((1/((double)(arr1)))*v);
System.out.println("the stdev is "+std);
}
 05302013, 04:02 PM #6Member
 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_algorithmLast edited by kalata; 05302013 at 04:55 PM.
 06042013, 01:45 PM #7Member
 Join Date
 May 2013
 Posts
 6
 Rep Power
 0
Re: help with sample program
I don't understand any thing how would you please help me finish this .
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
double[] grades=new double [n];
int[] S=new int[n+1];
int i,j ;
int s=1;
double sum=0.0;
double v=0.0;
for( i=0;i<grades.length;i++)
{
System.out.println("input the grade of Student "+(i+1));
grades[i]=in.nextDouble();
sum=sum+grades[i];
}
double average=sum/n;
System.out.println("the Average is "+average);
for(s=0;s<=n;s++)
{S[s]=S[s]+1;}
for ( i=1; i<grades.length1;i++){
for( j=0;j<grades.length1;j++){
if(grades[i]<grades[i+1]){
double temp=grades[i];
grades[i]=grades[i+1];
grades[i+1]=temp;
int tem=s=i;
s=s+1;
}
}
System.out.println("the student "+S[s]+"took the "+grades[i]);
v =v+(grades[i]  average) * (grades[i]  average);
}
System.out.print(grades[i]);
double std =Math.sqrt((1/((double)(n)))*v);
System.out.println("the stdev is "+std);
}
}
 06042013, 01:50 PM #8Member
 Join Date
 Jun 2013
 Posts
 1
 Rep Power
 0
Re: help with sample program
I want to suggest you https://www.udemy.com/javabasicsfo...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.
 06042013, 02:05 PM #9Member
 Join Date
 May 2013
 Posts
 6
 Rep Power
 0
Re: help with sample program
I don't understand any thing how would you please help me finish this .
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 double[] grades=new double [n]; int[] S=new int[n+1]; int i,j ; int s=1; double sum=0.0; double v=0.0; for( i=0;i<grades.length;i++) { System.out.println("input the grade of Student "+(i+1)); grades[i]=in.nextDouble(); sum=sum+grades[i]; } double average=sum/n; System.out.println("the Average is "+average); for(s=0;s<=n;s++) {S[s]=S[s]+1;} for ( i=1; i<grades.length1;i++){ for( j=0;j<grades.length1;j++){ if(grades[i]<grades[i+1]){ double temp=grades[i]; grades[i]=grades[i+1]; grades[i+1]=temp; int tem=s=i; s=s+1; } } System.out.println("the student "+S[s]+"took the "+grades[i]); v =v+(grades[i]  average) * (grades[i]  average); } System.out.print(grades[i]); double std =Math.sqrt((1/((double)(n)))*v); System.out.println("the stdev is "+std); } }
Last edited by JosAH; 06042013 at 02:08 PM. Reason: added [code] ... [/code] tags
 06062013, 10:41 AM #10Member
 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 double[] grades=new double [n]; 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;} for( i=0;i<grades.length ;i++) { System.out.println("input the grade of Student "+(i+1)); grades[i]=in.nextDouble(); sum=sum+grades[i]; } average=sum/n; for (j=0; j<n1;j++){ for(i=0 ,s=0;i<n1;i++,s++){ if(grades[i]<grades[i+1]){ double temp=grades[i]; grades[i]=grades[i+1]; grades[i+1]=temp; int tem=S[s]; S[s]=S[s+1]; S[s+1]=tem; } } v =v+(grades[i]  average) * (grades[i]  average); } 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'"); } } } }
Similar Threads

Sample Java Enterprise Program/Flowchart on Net ?
By dmaccormick in forum Forum LobbyReplies: 1Last Post: 01212013, 09:19 AM 
sample program for polymorphism
By murali23krishna in forum New To JavaReplies: 1Last Post: 08052010, 01:44 PM 
how to use jwnl.. i run a sample program it will ask properties file.. what can i do
By sathishk in forum New To JavaReplies: 1Last Post: 02162008, 04:33 AM
Bookmarks