Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-12-2008, 08:22 PM
Member
 
Join Date: Nov 2007
Location: Dublin, Ireland
Posts: 12
Mark1989 is on a distinguished road
Send a message via MSN to Mark1989
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..


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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-12-2008, 09:55 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,189
hardwired is on a distinguished road
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; } } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 03-12-2008, 09:59 PM
Member
 
Join Date: Nov 2007
Location: Dublin, Ireland
Posts: 12
Mark1989 is on a distinguished road
Send a message via MSN to Mark1989
Wow.. That is perfect thank you so much.

Actually understand it aswell cheers
__________________
Theres 10 types of people in this world, Those who understand binary and those who dont
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Array Help bluegreen7hi New To Java 2 03-28-2008 03:25 AM
Would appreciate your help with 2d Array.. cloudkicker New To Java 1 02-11-2008 03:34 PM
2D array bluekswing New To Java 2 01-15-2008 06:57 PM
Bounded Array bugger New To Java 4 01-04-2008 10:41 AM
Help with Array susan New To Java 1 08-07-2007 05:32 AM


All times are GMT +3. The time now is 07:43 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org