View Single Post
Old 10-09-2012, 09:25 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,645
Thanks: 4
Thanked 2,450 Times in 2,419 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
In the future, please wrap all code in [code][/code] or [php][/php] tags. It preserves the formatting.
Since this is an assignment, we can't just give you code. We can give suggestions though.
The first thing I'd suggest is actually changing high, low and average signatures:
Code:
public static double high(double[] a);
public static double low(double[] a);
public static double average(double[] a);
Arrays.sort will sort your array such that it will go from "smallest" to "highest" value. So with doubles, the lowest number will be the first, and the highest number is the last. You will need to check if an offset exists before accessing it, but that's a simple check on the length (assuming you haven't covered try/catch). Average is of course simply the sum of the array divided by the number of items within it. These changes will save you tonnes of code as they can be done in a little as one line of code (not looping required within the methods at all).

With the above changes, you could simply use them directly in the output if desired:
Code:
System.out.print(name[inc] + "\t\t");
System.out.print(high(gradebook[inc]) + "\t\t");
System.out.print(low(gradebook[inc]) + "\t\t");
System.out.print(average(gradebook[inc]) + "\t\t\n");
Note that the access level has changed from multidimensional to single dimension. This is because we do not want to factor in high, low, average, or grade numbers between multiple people; we only care about this specific iteration of student.

As for grade assignment, if its overall then you simply accept an double and use if/elseif syntax to assign a resulting letter and return that.

Nice work otherwise, it's looking good. Nice and clean. One thing to mention is that using a Scanner. Using nextInt/nextDouble methods (use nextDouble instead since you are calculating as double values), it does leave the linefeeds on the scanner. This isn't a problem here since you don't use the nextLine() function, but if you did you could pull an infinite loop if you use input for a looping control. Easily cleared by chomping the nextLine() or issuing a scanner clear.
Fou-Lu is offline   Reply With Quote