Results 1 to 3 of 3
Thread: can anyone help... 2d Array
- 03-12-2008, 07:22 PM #1
Member
- Join Date
- Nov 2007
- Location
- Dublin, Ireland
- Posts
- 12
- Rep Power
- 0
can anyone help... 2d Array
I am currently having a problem with a question i have for college. I have tried so much and still can only get half my question done can anyone help PLEASE!!
OK so my question is!
"You are required to write a program to monitor the grades of 4 students over 3 subjects. You should model this using a 2 dimensional array. At the end of each row output, you should also output the average grade of all students in that subject. Use random numbers to populate your array with grades between 1 and 100.
The three subjects are
Programming
Networking
Mathematics
The totals should be calculated for each row in order to determine the average grade.
A sample output would thus look like this:
B001 B002 B003 B004
Programing 90 50 100 60 Average: 75
Networking 80 40 80 40 Average: 60
Mathematics 30 60 30 60 Average: 45
Extend your program to include the following:
Determine and calculate the student number and subject of the highest grade across the board.
For example, in the above sample data the output should be
Student B003 scored the highest mark with 100% in Programming."
Now i Can get the table to print out its the second half i just cant get with the highest mark etc..
Java Code:class Arrays{ //opens program public static void main(String[]args){ int grades[][] = new int[3][4]; arraysone(grades); } static void arraysone(int a[][]){ int average=0; System.out.println("\t\tB001\tB002\tB003\tB004"); /////////////////////////// for(int r=0;r<3;r++) { System.out.println(); // New line for every row average = 0; Subject_Name(r); for(int c=0;c<4;c++) { a[r][c] = (int)(Math.random()* 10000)%100+1; System.out.print(a[r][c] + "\t"); average = average + a[r][c] / 4; } System.out.print(" Average: " + average); } ///////////////////////////// System.out.println("\n"); } /////////////////////////////////// // Process to add subject ////////////////////////////////////// static void Subject_Name(int sub){ switch(sub){ case 0:System.out.print("Programming\t");break; case 1:System.out.print("Networking\t");break; case 2:System.out.print("Mathematics\t");break; } } } //closes program
- 03-12-2008, 08:55 PM #2
Java Code:public class ArraysRx { public static void main(String[]args) { int grades[][] = new int[3][4]; arraysone(grades); showHighMark(grades); } private static void showHighMark(int[][] grades) { // grades array info organized by: // grades[subject][student] int highestGrade = -1; int subjectIndex = -1; int studentIndex = -1; for(int j = 0; j < grades.length; j++) { for(int k = 0; k < grades[j].length; k++) { if(grades[j][k] > highestGrade) { highestGrade = grades[j][k]; subjectIndex = j; studentIndex = k; } } } System.out.println("highestGrade = " + highestGrade + " " + " found at grades[" + subjectIndex + "]" + "[" + studentIndex + "] = " + grades[subjectIndex][studentIndex]); } static void arraysone(int a[][]) { int average=0; System.out.println("\t\tB001\tB002\tB003\tB004"); for(int r = 0; r < 3; r++) { System.out.println(); // New line for every row average = 0; Subject_Name(r); for(int c = 0; c < 4; c++) { a[r][c] = (int)(Math.random()* 10000)%100+1; System.out.print(a[r][c] + "\t"); average = average + a[r][c] / 4; } System.out.print(" Average: " + average); } System.out.println("\n"); } // Method to add subject static void Subject_Name(int sub){ switch(sub){ case 0: System.out.print("Programming\t"); break; case 1: System.out.print("Networking\t"); break; case 2: System.out.print("Mathematics\t"); break; } } }
- 03-12-2008, 08:59 PM #3
Member
- Join Date
- Nov 2007
- Location
- Dublin, Ireland
- Posts
- 12
- Rep Power
- 0
Similar Threads
-
Array Help
By bluegreen7hi in forum New To JavaReplies: 2Last Post: 03-28-2008, 02:25 AM -
Would appreciate your help with 2d Array..
By cloudkicker in forum New To JavaReplies: 1Last Post: 02-11-2008, 02:34 PM -
2D array
By bluekswing in forum New To JavaReplies: 2Last Post: 01-15-2008, 05:57 PM -
Bounded Array
By bugger in forum New To JavaReplies: 4Last Post: 01-04-2008, 09:41 AM -
Help with Array
By susan in forum New To JavaReplies: 1Last Post: 08-07-2007, 04:32 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks