Results 1 to 6 of 6
Thread: Array highest grade
- 05-05-2010, 08:31 PM #1
Member
- Join Date
- May 2010
- Posts
- 4
- Rep Power
- 0
Array highest grade
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 class ArrayGrades
{
public static void main(String[]args)
{
int[]Grade=new int[3];
int highestNumber = Grade.length;
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();
System.out.print("Enter the student's grade: ");
Grade[y]=scan.nextInt();
y++;
}
y=0;
while(y<7)
{
if(grade>=)
System.out.print("THE HIGHEST GRADE IS")RADE[Y];
y++;
}
}
}
- 05-05-2010, 08:44 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
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, 08:49 PM #3
Member
- Join Date
- May 2010
- Posts
- 4
- Rep Power
- 0
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, 09:05 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
- 05-05-2010, 09:18 PM #5
Member
- Join Date
- May 2010
- Posts
- 4
- Rep Power
- 0
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, 09:25 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
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':
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.Java Code:public class Student { private String name; private int grade; public Student(String name, int grade) { this.name= name; this.grade= grade; } // etc ... }
kind regards,
Jos
Similar Threads
-
Grade my questions, lol
By syntrax in forum New To JavaReplies: 4Last Post: 12-16-2009, 06:03 AM -
QuickSort highest lowest Situation
By Tenn in forum New To JavaReplies: 17Last Post: 05-06-2009, 04:37 AM -
[SOLVED] Help with arrays, printing highest and lowest value of the array.
By Sophiie in forum New To JavaReplies: 21Last Post: 11-05-2008, 02:31 PM -
Finding the highest number
By jigglywiggly in forum New To JavaReplies: 7Last Post: 11-04-2008, 08:14 AM -
The highest number
By I-Shine in forum Java AppletsReplies: 3Last Post: 02-13-2008, 05:05 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks