Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Help needed on java array

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help needed on java array

    I have an assignment on arrays
    On student grades .
    The Program should provide the following.
    1. Allow a user to enter a number of results (a value between 2 & 25)

    2. Process the required number of results by

    • Allowing a user to enter a students name
    • Allowing a user to enter a students grade (a value between 1 & 100).

    3. When data entry is complete, display a menu with the following options

    • Display lowest class grade
    • Display highest class grade
    • Display average class grade
    • Sort & Display the grades in ascending order
    • Search for an individual student by name

    Can someone point me in the right direction with this program .
    thanks john


  2. #2
    Junior Member
    Join Date
    Mar 2010
    Location
    Mauritius
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help needed on java array

    Hi John

    From what I understand, you just need the following

    1. Implement main method
    2.Accept the number of results , n.
    3.Check whether n is greater than 2 and less than 25
    4. Loop the number of results to enter and accept the grades, in an array, for example.
    5.Print the following options in the screen.

    If you are facing some probs, please put your code forward.

    Cheers,
    wanderer
    (prit4u.wordpress.com)

  3. #3
    Junior Member
    Join Date
    Mar 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help needed on java array

    This is what i have done so far but when i enter more that 4 students the programs closes down also where would i enter the sort code ?
    public class program {
     
     
            public static void main(String[] args) {
     
     
                // Establishes the rows and columns in the arrays,
                // along with the average grades.
                int students = 0, tests = 0;
                int sum = 0;
                // Establishes an array for student names, test grades and averages, and
                // the final letter grade.
     
               int grade[][] = new int[25][3];
                String student[] = new String[25];
                double low=100;
                double high=0;
                double low1[]={100,100,100} ;
                double high1[]={0,0,0} ;
     
                // This allows to set the number of students and test grades that you can enter.
                System.out.println("Please enter the number of students you want to enter(1-25): ");
                students = EasyIn.getInt();
     
     
                System.out.println("Please enter the number of test  subject grades (1-3): ");
                tests = EasyIn.getInt();
     
                System.out.println();
                // This allows you to enter the student name, and their test grades.
                for( int x = 0; x < students; x++){
                    System.out.println("Student Name: ");
                    student[x] = EasyIn.getString();
     
                    for(int y = 0; y < tests; y++){
                        System.out.println("Test Grade " +(y + 1) +": ");
                        grade[x][y] = EasyIn.getInt();
     
                        if (low1[x] > grade[x][y])
                        {
                            low1[x] = grade[x][y];
                        }
     
                        if (high1[x] < grade[x][y])
                        {
                            high1[x] = grade[x][y];
                        }
     
                        sum += grade[x][y];
     
                        if (grade[x][y] < low)
                            low = grade[x][y];
                        if (grade[x][y] > high)
                            high = grade[x][y];
                    }
     
                    // Determines grade letter from the average score of each student.
                    grade[x][tests] = sum/tests;
     
     
                    sum = 0;
                    System.out.println();
                    }
     
                    // Out
                    System.out.printf("%-10s","Student Name" + "\t");
                    for(int y = 0; y < tests; y++){
                        System.out.printf("%-10s", "Test " + (y + 1));
                    }
                    System.out.println("    Average        Grade  lowest grade");
                    for(int q = 0; q < students; q++){
                        System.out.printf("%-12s", student[q]);
                        for(int w = 0; w < tests; w++){
                            System.out.printf("%10.2f", grade[q][w]);
                        }
                        System.out.printf("%12.2f", grade[q][tests]);
     
                        System.out.printf("%16s", low1[q]);
                        System.out.printf("%13s", high1[q]);
     
                        System.out.println();
     
                    }
    //
     
            String search_name;
                    System.out.printf("Please enter student Name to search for: ");
                    search_name = EasyIn.getString();
                 for(int q = 0; q < students; q++){
                if (student[q].equals(search_name))
                    {
                    System.out.printf("Student Name: %s \n", student[q]);
     
                        for(int r = 0; r < tests; r++)
                        {
                            //System.out.printf("%10.2f", grade[q][r]);
                            System.out.printf("\n Test %d : Mark : %.2f  ",r + 1 , grade[q][r]);
                        }
                        System.out.printf("\n\n Lowest mark by %s in all tests  : %.2f \n Highest mark by %s in all tests %.2f \n",search_name, low1[q],search_name,high1[q]);
                    }
     
     
                      //
                }
                      //
                 System.out.printf("\n\n Lowest overall mark by any student in all tests  : %.2f \n Highest overall mark by any student in all tests %.2f \n",low,high);
    }
            ///
    Last edited by helloworld922; March 7th, 2010 at 03:09 PM.

Similar Threads

  1. Multi Dimensional Array help NEEDED URGENT
    By bonjovi4u in forum Loops & Control Statements
    Replies: 5
    Last Post: February 13th, 2010, 12:44 AM
  2. array program assistance needed
    By JavaNoob82 in forum Collections and Generics
    Replies: 4
    Last Post: December 14th, 2009, 05:49 AM
  3. Array program help needed
    By SCM in forum Loops & Control Statements
    Replies: 2
    Last Post: December 2nd, 2009, 11:28 PM
  4. Urgent Help needed with java codes
    By makarov in forum Java Theory & Questions
    Replies: 0
    Last Post: November 13th, 2009, 07:23 AM
  5. Java NullPointer Exception in Server chat program
    By Valtros in forum Exceptions
    Replies: 1
    Last Post: May 8th, 2009, 05:06 AM