Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: java gradebook

  1. #1
    Junior Member
    Join Date
    Dec 2009
    Location
    AL
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default java gradebook

    hi,

    i have been working on a java gradebook that uses traversals, insertions, deletions, and such. i have really just started working and have ran into a few little problems. im kind of working on it in a weird order, so please excuse that.

    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    /**
     *
     * @author chsstudent
     */
    public class student {
        String StudentName;
        int qz1;
        int qz2;
        int qz3;
        int qz4;
        int qz5;
     
        public student (String name, int q1, int q2, int q3, int q4, int q5)
        {
            StudentName = name;
            qz1 = q1;
            qz2 = q2;
            qz3 = q3;
            qz4 = q4;
            qz5 = q5;
        }
     
     
        public void setQuiz ()
        {
     
     
     
        }
     
        public int getQuiz (int q1, int q2, int q3, int q4, int q5)
        {
     
     
         return 
     
        }
     
     
        public void toString(String name, int q1,
                int q2, int q3, int q4, int q5)
        {
            System.out.println(" Name = " + name +
                    " Q1 = " + q1 + " Q2 = " + q2 +
                    " Q3 = " + q3 + " Q4 = " + q4 +
                    " Q5 = " + q5);
     
        }
     
    }

    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    /**
     *
     * @author chsstudent
     */
    public class testStudent {
     
     
     
     
     
        student[] grades = new student[5];
     
        //create gradebook
        grades[0] = new student("Mark", 70, 80, 90, 100, 90);
        grades[1] = new student("Max", 80, 85, 90, 85, 80);
        grades[2] = new student("Jean", 50, 79, 89, 99,100);
        grades[3] = new student ("Betty", 85, 80, 85, 88, 89);
        grades[4] = new student ("Dilbert", 70, 70, 90, 70, 80);
     
     
     
     
     
     
     
        }
    my actual problem as of now is that im getting errors on my tester class's arrays. if anyone can spot whats wrong with them it would be greatly appreciated. i really dont know whats wrong with them considering i copied them from examples.

    ---------------------------------------------------------edit------------------------------------
    figured out this code, got it working using this
    import java.util.*;
    public class testStudent
    {
     
        public static void main(String [] args)
        {
            ArrayList<student> quizzes = new ArrayList<student>();
            quizzes.add(new student("Mark", 70, 80, 90, 100, 90));
            quizzes.add(new student("Max", 80, 85, 90, 85, 80));
            quizzes.add(new student("Jean", 50, 79, 89, 99,100));
            quizzes.add(new student("Betty", 85, 80, 85, 88, 89));
            quizzes.add(new student("Dilbert", 70, 70, 90, 70, 80));
        }
     
    }

    im now trying to work on my uncompleted methods in my student class. having alot of trouble figuring out the best way to "set" and "get" each quiz score.if anyone has any advice on a good way to do this it would be appreciated. thanks.
    Last edited by gibson.nathan; December 13th, 2009 at 10:02 PM.


  2. #2
    Member
    Join Date
    Aug 2009
    Posts
    53
    Thanks
    2
    Thanked 3 Times in 2 Posts

    Default Re: java gradebook

    Hello gibson.nathan
    First:
    In your student class, your toString method are taking parameters, which it shouldn't.
    You have should simply return a string containing the info you deem interesting/useful about the object.
    When you get further into inheritance, you will see in more detail what role the toString method fulfills.

    Ok so about getting and setting test scores. The problem here is we want some sort of datastructure, so it is possible to give a name, then get the student with that name, then set/get one of the students test results.
    It is really hard to determine the "best" solution for any given problem, but a solution could involve a Map rather than a List. HashMap for example.
    Java 2 Platform SE 5.0

    You add objects to a map just like the arraylist, but here you assign an object with a key, you also use to retrieve that object.
    studentmap.put("studentname", student)

    Your student could then have standard get / set methods for each test, to change read og write to the test fields.

    Feel free to ask further questions if that was confusing.