I have a project for school and I cant figure out what to do. I need all the help I can get. Its due tonight and I am stumped. I have spent 7hrs on it today already and Im stumped 100%. Here is the assignment. We use Netbeans to write.


The elementary school for which you are doing development work has asked you to create a program to store quiz grades for the students of a class. The program should prompt the teacher to input a student number. The quiz score for that student will be displayed. The program can prompt for each quiz score or the scores can be preloaded or hard-coded into the program. Your solution must include an array. Your solution must include 5 parts in addition to the coded solution.

Thank you so much for any help. Email me directly at <email snipped> with anything you come up with.


Sorry I dont know how to make it come out with all the numbers on the side and all that. Im a JAVA newbie.
Here is what I have so far:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ip5;
import java.util.Scanner;

/**
 *
 * @author Ed
 */
public class Main {

    public static void main(String[] args) {
        
        int[] student;  
        // declares an array of integers
          
          student = new int[10];      
          // allocates memory for 10 integers
            
          student[0] = 92; // initialize first element
          student[1] = 88; // initialize second element
          student[2] = 75; // etc.
          student[3] = 97;
          student[4] = 93;
          student[5] = 72;
          student[6] = 66;
          student[7] = 90;
          student[8] = 89;
          student[9] = 80;
                    {
          for (int x=0 ; x >100 ; x++){
          System.out.println("The grade of student number" + x + "is "  + student[x]);
          System.out.println("Student number 0 has a grade of: " + student[0]);
          System.out.println("Student number 1 has a grade of: " + student[1]);
          System.out.println("Student number 2 has a grade of: " + student[2]);
          System.out.println("Student number 3 has a grade of: " + student[3]);
          System.out.println("Student number 4 has a grade of: " + student[4]);
          System.out.println("Student number 5 has a grade of: " + student[5]);
          System.out.println("Student number 6 has a grade of: " + student[6]);
          System.out.println("Student number 7 has a grade of: " + student[7]);
          System.out.println("Student number 8 has a grade of: " + student[8]);
          System.out.println("Student number 9 has a grade of: " + student[9]);

          
                
        
    
    }
                    }

So needless to say I cant figure out the coding to put for the teacher to enter the student number and have the program display the students grade. I am totally baffled.

We can't do it all for you and send you the solution for money. It's not that kind of forum. I doubt you are going to be able to get it done in seven hours if you have no idea of how to do it. Here's a skeleton that could be helpful:

public class ClassGrades
{
     Student[] students;
     Scanner scanner;
     
     public ClassGrades ()
     {
           // create students array and scanner
           Menu ();
     }


     public void Menu ()
     {
          boolean quit = false;
          do
          {
               // ask user whether he/she wants to display a student or quit
               if (!quit)
                    DisplayStudent ();
          }
          while (!quit);
     }


     public void DisplayStudent ()
     {
          // prompt for student number
          Student student = // code
          student.DisplayGrades ();
     }


     public static void main (String args[])
     {
          new ClassGrades ();
     }
}


class Student
{
     int studentNumber;
     int[] grades;

     public Student (int sudentNum, int[] studentGrades)
     {
          // code
     }


     public DisplayGrades ()
     {
          // code
     }
}

Ya that doesnt help me at all. Im an online student and I missed the chat. They are recorded but for some odd reason this chat is totally lost in cyber space. It starts but at about 15mins its just gone. So needless to say I am set adrift without a paddle and I am rapidly sinking. If I dont do good on this assignment I fail the class and thats $2000 down the drain. I have done great on all the other programs we had to write but I am totally lost on this one and Im very discouraged.

Ya that doesnt help me at all.

Look, I understand your frustration, but like I said, this isn't the kind of site where people do the whole assignment for you. You can try "Rent a Coder" or something, but even there it's doubtful you'll get a seven hour turnaround.

I assume my skeleton doesn't help you at all because you don't know the basics of Java. Otherwise it should at least help you some. Anyway, if you need more help, you need to ask a more specific question.

I think it doesnt help me because I am just so frustrated and feel like all hope is lost at this point. I do understand basic java but I struggle. Its alot of work for me. This isnt even part of my degree just a class I have to take.

Basically I dont know what line of code I need so the teacher can enter a student number and then have that students corresponding test grade retrieved. I have tried everything I know to no avail.

To read teacher input you need to use Scanner class.
As for students records I would recommend to use 2D array instead of simple one

int[][] student = {{1111, 92}, {1234, 88},{2345, 75}};

first number is student unique ID {1111} and second is the mark {92}

Okay well here is what I have now. I am rewriting everything with everyones suggestions.

public static void main(String[] args) {
      int[][] student;
      student = new int[2][10];

student[0][0] = 0; // the student number for student 0
student[0][1]= 92;   // student 0's score
student[1][0]= 1;// student number for student 1
student[1][1]= 87;//student 1's score
student[2][0]= 2;//student number for student 2
student[2][1]=97;//student 2's score
student[3][0]= 3;
student[3][1]= 84;
        
        

        String userInput = null; 
boolean quit = false;
while (!quit) {

    System.out.print("Enter the student number you wish to retrieve ->"); 
         
try { 
             userInput = br.readLine(); 
          } catch (IOException ioe) { 
             System.out.println("IO error trying to read your name!"); 
             System.exit(1); 
          } 
int xx = 0;
if (userInput.toUpperCase().equals("QUIT) quit = true;
if (!quit) {
     try {
           xx = Integer.parseInt(userInput);
        } catch (NumberFormatException e) {
            // TODO Auto-generated catch block
          System.out.println("Student number must be an integer");
        }
/* Now search for the student number */
boolean found = false;
int z = 0;
while ((!found) && (z < 10)) {
if (student[0][z] == xx) found = true;
else z++;
}
if (found) System.out.println("The student number is ->"+student[1][z];
else
System.out.println("There is no student with that student number.   Please try again");

    }

}

This was with tons of help from a friend. But im still stumped on it because I cant get it to run.

try { 
        userInput = br.readLine();
}

I do not see declaration of "br" anywhere in the code

if (userInput.toUpperCase().equals("QUIT")) quit = true;

Missing closing double quote and closing round bracket

if (found) System.out.println("The student number is ->"+student[1][z]);

Missing closing round bracket

On the end of provided code you missing one curly bracket (maybe missed while copy&paste, but check it just in case)

See we havent even covered Boolean in class yet. It was a suggestion from a friend. He said it would be the easiest route to go. Im not sure why.

I dont know what "br" is.

I found those mistakes after I posted. Thanks. Im just not sure how to continue the program.

Basically my teacher said here you go good luck. Im trying my best but I am struggling mightly as you can tell.

I misread the original specification:

The elementary school for which you are doing development work has asked you to create a program to store quiz grades for the students of a class. The program should prompt the teacher to input a student number. The quiz score for that student will be displayed. The program can prompt for each quiz score or the scores can be preloaded or hard-coded into the program. Your solution must include an array. Your solution must include 5 parts in addition to the coded solution.

I was originally under the impression that each student had more than one score. Reading it again, it appears that there is one score per student. Thus if you create a Student class, it should probably have these data members:

int studentNumber;
int grade;

rather than:

int studentNumber;
int[] grades;

as I originally suggested. So I would make that change if you decide to use a Student class. The part that I would definitely change from your code to make it closer to mine is that all of your code is in main, whereas my skeleton uses a Student class and a ClassGrades class. You may decide to drop the Student class (if you follow peter_budo's advice of a 2-D array, which you are doing, don't use a Student class), but you should really not have all of this in main, in my opinion. Declare the 2-dimensional array as a data member of the class and have the main function simply call a constructor of that class, as my skeleton does. Right now you have no functions, which makes your program more and more unmanageable as it gets bigger.

See we havent even covered Boolean in class yet. It was a suggestion from a friend. He said it would be the easiest route to go. Im not sure why.

I dont know what "br" is.

I found those mistakes after I posted. Thanks. Im just not sure how to continue the program.

Basically my teacher said here you go good luck. Im trying my best but I am struggling mightly as you can tell.

I imaging br stands for BufferedReader
http://java.sun.com/javase/6/docs/api/java/io/BufferedReader.html

Don't use it if you don't have to. It's one more thing to learn. Stick with Scanner.

http://www.roseindia.net/java/java-tips/examples-introductory/console/console-input-scanner.shtml

I've heard roseindia isn't the best site to link to, but it was the most basic example that I found in the google search. Here's the Java doc page.

http://java.sun.com/javase/6/docs/api/java/util/Scanner.html

This article has been dead for over six months. Start a new discussion instead.