View Single Post
Old 10-09-2012, 07:06 PM   PM User | #1
b721991
New to the CF scene

 
Join Date: Oct 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
b721991 is an unknown quantity at this point
Multidimensional Array and Seperate Methods

This is a gradebook that is suposed receive so many grades and I'm having a hard time getting the high grade, low grade and average, I also need the Letter grade from the average. Can you please help:/

import java.util.*;
public class P_MidtermProject {


public static void main(String[] args) {
int outercounter=0;
int howMany=0;
Scanner input = new Scanner(System.in);

System.out.print("How many students are there?: ");
int numStudents = input.nextInt();
String name [] = new String[numStudents];
System.out.print("Enter the number of grades for the semester: ");
howMany = input.nextInt();
double [][] gradebook = new double [numStudents][howMany];


for(outercounter = 0; outercounter<name.length; outercounter++ ){

System.out.print("Enter the students name: ");
String studentName = input.next();
name[outercounter]=studentName;


for(int innercounter = 0; innercounter<howMany; innercounter++){

System.out.print("Enter grade: ");
int grade = input.nextInt();
gradebook[outercounter][innercounter]=grade;

}//end of inner loop

}//end of outer loop
System.out.println("Student Name\tHigh Score\tLow Score\tAverage\t\tGrade");
System.out.println("");
for(int inc = 0; inc<name.length;inc++){
high(gradebook);
System.out.print(name[inc] + "\t\t");
System.out.print(gradebook[inc][0]+"\t\t");
low(gradebook);
System.out.print(gradebook[inc][0]+"\t\t");
average(gradebook);
System.out.print(gradebook[inc][0]+"\t\t\n");}


}//end of main
public static void high(double a[][]){


for(int nn=0;nn<a.length;nn++){
Arrays.sort(a[nn]);
for(int counter=0; counter<a.length-1; counter++ ){
for(int count=0; count<a[counter].length-1; count++ ){
if (a[counter][count+1] < a[counter][count]){
double tempG = a[counter][count];
a[counter][count] = a[counter][count+1];
a[counter][count+1] = tempG;


}//end of if
}//end of inner loop
}//end of outer loop


}//end of for





}//end of high
public static void low(double a[][]){
for(int count=0;count<a.length;count++){
Arrays.sort(a[count]);

}//end of for


}//end of low

public static void average(double a[][]){
double average = 0;
for (int inc=0; inc<a.length;inc++){

for (int inctwo=0;inctwo<a[0].length;inctwo++){
average = average + a[inc][inctwo];}//end of inner loop

a[inc][0] = average/a[inc].length;
average=0;

}//end of for



}//end of average



}//end of class
b721991 is offline   Reply With Quote