DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   Could somebody help me please with java program? (http://www.daniweb.com/forums/thread139520.html)

drum12 Aug 10th, 2008 2:27 pm
Could somebody help me please with java program?
 
I have two arrays. In the first one I have student surnames, in second the student grades. (One surname one line with grades).My task is to find the arithmetic average for each student and print that student name and grade which have the biggest grade in array. I wrote the program which can find arithmetic average for one student and print his name and grade. Can somebody help to write another part of program? Here is text of my program:
package md4;
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
         
                        String surnames[]=
    {"Alksnis", "Berzinsh", "Celms", "Dadzis", "Eglitis", "Zalitis"};
                    int grades [][] = {
            {6, 6, 7, 7, 8, 5},
            {5, 6, 4, 9, 5, 7},
            {6, 6, 5, 6, 6, 7},
            {9, 8, 8, 9, 9, 8},
            {8, 7, 7, 8, 8, 7},
            {7, 5, 6, 5, 7, 6}
        };         
          double result = 0;
            int u; 
            double arifm;
            int i=0,j=0; //i=row, j=column
                                 
              Scanner input = new Scanner( System.in );
             
    System.out.println("0. Alksnis, 1. Berzinsh, 2. Celms, 3. Dadzis, 4. Eglitis, 5. Zalitis");
                // surnames
    i = input.nextInt(); // read number from user
             
              System.out.println("priekkshmetu skaits no 1-6");
                u = input.nextInt(); // read number from user
                   
                for (j=0; j<u; j++) //choise how many grades
             
                    result= result + grades [i][j];  //summ of elements
             
                    arifm = result / j;
             
                        System.out.println(surnames [i]+ " arithmetic average is  "  +arifm );

    }
}
Sorry about my English :)

VernonDozier Aug 10th, 2008 4:07 pm
Re: Could somebody help me please with java program?
 
You have a 6 x 6 array of grades. You have the code that computes the average for one person. You need to compute the average for all six, so stick that code into a loop that executes 6 times (once per person). Have a variable called
highestAverage
. Initialize it to the average of the first person. As you compute each average, compare
arifm
to
highestAverage
. If
arifm
is bigger than
highestAverage
, set
highestAverage
to
arifm
. When you are done with the loop, you'll have the highest average stored in
highestAverage
.


All times are GMT -4. The time now is 3:23 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC