Results 1 to 10 of 10
  1. #1
    mounir is offline Member
    Join Date
    May 2013
    Posts
    6
    Rep Power
    0

    Lightbulb 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 .

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,775
    Blog Entries
    7
    Rep Power
    21

    Default 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
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    mounir is offline Member
    Join Date
    May 2013
    Posts
    6
    Rep Power
    0

    Default 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. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,775
    Blog Entries
    7
    Rep Power
    21

    Default Re: help with sample program

    Quote Originally Posted by mounir View Post
    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;
    while (<more to read>) {
       double x= <read a number from the user>;
       Xi+= X;
       Xi2+= X*X;
       n++;
    }
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    mounir is offline Member
    Join Date
    May 2013
    Posts
    6
    Rep Power
    0

    Default 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)(arr-1)))*v);
    System.out.println("the stdev is "+std);
    }

  6. #6
    kalata is offline Member
    Join Date
    Aug 2011
    Location
    Bulgaria
    Posts
    29
    Rep Power
    0

    Default 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. #7
    mounir is offline Member
    Join Date
    May 2013
    Posts
    6
    Rep Power
    0

    Default 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.length-1;i++){
    for( j=0;j<grades.length-1;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);
    }
    }

  8. #8
    richakapoor is offline Member
    Join Date
    Jun 2013
    Posts
    1
    Rep Power
    0

    Default 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. #9
    mounir is offline Member
    Join Date
    May 2013
    Posts
    6
    Rep Power
    0

    Default 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.length-1;i++){ 
                             for( j=0;j<grades.length-1;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; 06-04-2013 at 02:08 PM. Reason: added [code] ... [/code] tags

  10. #10
    mounir is offline Member
    Join Date
    May 2013
    Posts
    6
    Rep Power
    0

    Default 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<n-1;j++){ 
                             for(i=0 ,s=0;i<n-1;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

  1. Sample Java Enterprise Program/Flowchart on Net ?
    By dmaccormick in forum Forum Lobby
    Replies: 1
    Last Post: 01-21-2013, 09:19 AM
  2. sample program for polymorphism
    By murali23krishna in forum New To Java
    Replies: 1
    Last Post: 08-05-2010, 01:44 PM
  3. Replies: 1
    Last Post: 02-16-2008, 04:33 AM

Posting Permissions

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