Thread: can anyone help... 2d Array

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){

}

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");

}

///////////////////////////////////
//////////////////////////////////////
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```

2. Java Code:
```public class ArraysRx {
public static void main(String[]args) {
}

private static void showHighMark(int[][] grades) {
// grades array info organized by:
int subjectIndex = -1;
int studentIndex = -1;
for(int j = 0; j < grades.length; j++) {
for(int k = 0; k < grades[j].length; k++) {
subjectIndex = j;
studentIndex = k;
}
}
}
" found at 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");
}

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;
}
}
}```

3. Member
Join Date
Nov 2007
Location
Dublin, Ireland
Posts
12
Rep Power
0
Wow.. That is perfect thank you so much.

Actually understand it aswell cheers :)

Posting Permissions

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