Results 1 to 6 of 6
  1. #1
    Cdlove is offline Member
    Join Date
    May 2010
    Posts
    4
    Rep Power
    0

    Default 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++;





    }
    }
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,560
    Blog Entries
    7
    Rep Power
    21

    Default

    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

  3. #3
    Cdlove is offline Member
    Join Date
    May 2010
    Posts
    4
    Rep Power
    0

    Default

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

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,560
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Cdlove View Post
    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

  5. #5
    Cdlove is offline Member
    Join Date
    May 2010
    Posts
    4
    Rep Power
    0

    Default

    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.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,560
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Cdlove View Post
    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':

    Java 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

Similar Threads

  1. Grade my questions, lol
    By syntrax in forum New To Java
    Replies: 4
    Last Post: 12-16-2009, 06:03 AM
  2. QuickSort highest lowest Situation
    By Tenn in forum New To Java
    Replies: 17
    Last Post: 05-06-2009, 04:37 AM
  3. Replies: 21
    Last Post: 11-05-2008, 02:31 PM
  4. Finding the highest number
    By jigglywiggly in forum New To Java
    Replies: 7
    Last Post: 11-04-2008, 08:14 AM
  5. The highest number
    By I-Shine in forum Java Applets
    Replies: 3
    Last Post: 02-13-2008, 05:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •