Could somebody help me please with java program?

Reply

Join Date: Jun 2008
Posts: 1
Reputation: drum12 is an unknown quantity at this point 
Solved Threads: 0
drum12 drum12 is offline Offline
Newbie Poster

Could somebody help me please with java program?

 
0
  #1
Aug 10th, 2008
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:
  1. package md4;
  2. import java.util.Scanner;
  3. public class Main {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. String surnames[]=
  8. {"Alksnis", "Berzinsh", "Celms", "Dadzis", "Eglitis", "Zalitis"};
  9. int grades [][] = {
  10. {6, 6, 7, 7, 8, 5},
  11. {5, 6, 4, 9, 5, 7},
  12. {6, 6, 5, 6, 6, 7},
  13. {9, 8, 8, 9, 9, 8},
  14. {8, 7, 7, 8, 8, 7},
  15. {7, 5, 6, 5, 7, 6}
  16. };
  17. double result = 0;
  18. int u;
  19. double arifm;
  20. int i=0,j=0; //i=row, j=column
  21.  
  22. Scanner input = new Scanner( System.in );
  23.  
  24. System.out.println("0. Alksnis, 1. Berzinsh, 2. Celms, 3. Dadzis, 4. Eglitis, 5. Zalitis");
  25. // surnames
  26. i = input.nextInt(); // read number from user
  27.  
  28. System.out.println("priekkshmetu skaits no 1-6");
  29. u = input.nextInt(); // read number from user
  30.  
  31. for (j=0; j<u; j++) //choise how many grades
  32.  
  33. result= result + grades [i][j]; //summ of elements
  34.  
  35. arifm = result / j;
  36.  
  37. System.out.println(surnames [i]+ " arithmetic average is " +arifm );
  38.  
  39. }
  40. }
Sorry about my English
Last edited by Ancient Dragon; Aug 10th, 2008 at 4:59 pm. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,765
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 493
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: Could somebody help me please with java program?

 
0
  #2
Aug 10th, 2008
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 .
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC