Results 1 to 2 of 2
  1. #1
    newtocs is offline Member
    Join Date
    Oct 2009
    Posts
    1
    Rep Power
    0

    Question Project Question Urgent?

    So I'm making this gradebook project and I'm so close to being finished but I'm stuck on how to remove a student from the array. I have to display a list of students and let the user select one (already done), i just don't know how i would take out that student. I know i need to change the length of the array and take the student out, I just don't know how. HELP!! thanks sorry gotta add the code
    Code

    public static void removeStudent(String []studentName, int [] studentGrade, int size){
    int choice;
    for (int i=0; i<size; i++){
    System.out.print (i +" "+studentName [i]+" "+studentGrade[i]);
    }
    System.out.print ("Which student would you like to remove?");
    choice = kb.nextInt();
    }

    ya it's in methods just assume everything else works heres the beginning
    int choice;
    int size = 0;
    String studentName[]= new String [25];
    int studentGrade[]= new int [25];



    out.println("Please enter your name");//Allows user to make choice
    String name = kb.nextLine();
    do {
    out.println("\n\n*******" + name + "'s Gradebook*******");
    out.println("1. Add a student");
    out.println("2. Update a student's grade");
    out.println("3. Remove a student");
    out.println("4. View the gradebook");
    out.println("5. Display the highest grade");
    out.println("6. Quit");
    out.print("\nPlease enter your selection: ");

    choice = kb.nextInt();

    //Clears the buffer
    kb.nextLine();

    switch(choice) {
    case 1://Add a student
    addStudent(studentName, studentGrade, size);
    size ++;
    break;

    case 2:// Update a student's grade
    updateGrade (studentName, studentGrade, size);

    break;

    case 3: //Remove a student.

    break;

    case 4://View the gradebook.
    viewBook (studentName, studentGrade, size);

    break;

    case 5://Display the highest grade.
    HighGrade (studentName, studentGrade, size) ;

    break;
    case 6://Quit
    out.println("Thanks for using the FriscoCorp system.");

    }
    }while(choice != 6);
    Last edited by newtocs; 10-09-2009 at 05:32 AM. Reason: cause i messed up

  2. #2
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default

    you can't change the length. Arrays have a fixed size ArrayLists are dynamic and can be changed on the fly. To remove a student from the list you can just set array[i] = null, where i = the students location.
    Liberty has never come from the government.
    Liberty has always come from the subjects of government.
    The history of liberty is the history of resistance.
    The history of liberty is a history of the limitation of governmental power, not the increase of it.

Similar Threads

  1. Urgent! Need help for my final year project!!
    By kazuma_riku73 in forum Sun Java Wireless Toolkit
    Replies: 7
    Last Post: 06-18-2010, 11:48 AM
  2. Urgent! Need help for my final year project!!
    By kazuma_riku73 in forum Sun Java Wireless Toolkit
    Replies: 1
    Last Post: 01-15-2009, 11:14 AM
  3. Replies: 0
    Last Post: 09-28-2008, 11:02 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
  •