• 05-05-2010, 09:31 PM
Cdlove
Hey i need help with a program that will use an array that takes in numbers and names and outputs the highest grade and the name of the highest grades holder. Here is what I have so far.

import java.util.Scanner;
{
public static void main(String[]args)
{
String[]name=new String[3];
int y=0;

Scanner scan=new Scanner(System.in);

while(y<7)
{
System.out.print("Enter students name ");
name[y]=scan.next();

y++;
}

y=0;
while(y<7)
{
y++;

}
}
}
• 05-05-2010, 09:44 PM
JosAH
This doesn't answer your question but nevertheless: what are those numbers 3 and 7 doing in your code? They are 'magic numbers' because nobody knows what they mean. You know and maybe your teacher knows but ... let your code be prepared to store 11 students and their grades or 42 of them. For now any fixed number will do.

kind regards,

Jos
• 05-05-2010, 09:49 PM
Cdlove
Actually those "3" are supposed to be "7", disregard the 3's and protend they are 7's. That help you any?
• 05-05-2010, 10:05 PM
JosAH
Quote:

Originally Posted by Cdlove
Actually those "3" are supposed to be "7", disregard the 3's and protend they are 7's. That help you any?

Not really but thou art forgiven but keep those nasty 'magic numbers' in mind; real programmers don't want to see them, none of them ;-) Now, what exactly is your problem? Use just plain word and no code nor any fragments thereof.

kind regards,

Jos
• 05-05-2010, 10:18 PM
Cdlove
Alright, so I have to make a basic gradebook, in which I need to include 7 to 27 grades and names to the grades(this is all in an array by the way). When all is said and done with the array, it has to output(print) the highest grade and the grades owner.
• 05-05-2010, 10:25 PM
JosAH
Quote:

Originally Posted by Cdlove
Alright, so I have to make a basic gradebook, in which I need to include 7 to 27 grades and names to the grades(this is all in an array by the way). When all is said and done with the array, it has to output(print) the highest grade and the grades owner.

Java is an OO language so don't you think a little class is appropriate here? A class that holds a name (String) as well as a grade (int)? Something like this comes up sort of 'natural':

Code:

```public class Student {   private String name;   private int grade;   public Student(String name, int grade) {       this.name= name;       this.grade= grade;   }   // etc ... }```
You can stick all those Student objects in an array and fiddle diddle with them to solve your problem. How about that scenario? Of course you can augment that Student class as needed.

kind regards,

Jos