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.

Page 2 of 2 FirstFirst 12
Results 26 to 28 of 28

Thread: StudentQuizzesObject

  1. #26
    Member llowe29's Avatar
    Join Date
    Jul 2013
    Posts
    116
    My Mood
    Tired
    Thanks
    9
    Thanked 5 Times in 5 Posts

    Default Re: StudentQuizzesObject

    i figured out wasnt asking right questions

  2. #27
    Member llowe29's Avatar
    Join Date
    Jul 2013
    Posts
    116
    My Mood
    Tired
    Thanks
    9
    Thanked 5 Times in 5 Posts

    Default Re: StudentQuizzesObject

    New problem after speaking with my teacher emerge.
    /**
     * Write a description of class Student here.
     * 
     * @author (Landon L.) 
     * @version (a version number or a date)
     */
    public class Student
    {
        // instance variables - replace the example below with your own
        private String name;
        private int qz1;
        private int qz2;
        private int qz3;
        private int qz4;
        private int qz5;
        private int [] grade;
        /**
         * Constructor for objects of class Student
         */
        public Student(String name, int q1, int q2, int q3, int q4, int q5)
        {
            // initialise instance variables
            this.name = name;
            qz1 = q1;
            qz2 = q2;
            qz3 = q3;
            qz4 = q4;
            qz5 = q5;
        }
           //Given these  rules, how would I be able to create these methods(below)??? I mean you cant use an array and only certain instance variables
           //are allowed.
          // Student will need instance variables name , qz1, qz2, qz3, qz4, and 
         //qz5 (of types String and int, respectively). 
         // Student will need appropriate methods and constructors. To make things 
         //interesting, create a getQuiz() method that takes in a quiz number as input and 
         //then returns the appropriate quiz value. Likewise, setQuiz() will take as input 
         //a quiz number and quiz score, and then put the value into the right variable. Make 
         //sure to have a toString() method that prints the name of the student along 
         //with the quiz scores. 
        public int getQuiz(int num)
        {
    // this is what I am not sure of
            grade = new int[5];
             return grade[num-1];
        }
     
        public void setQuiz(int num, int[] gr )
        {
          if(num < 1||num > 5)
          {
          String msg = " This quiz doesn't exist. ";
          throw new IllegalArgumentException(msg); 
          }
             qz1 = gr[num-1];
             qz2 = gr[num-1];  
             qz3 = gr[num-1];       
             qz4 = gr[num-1];
             qz5 = gr[num-1];
        } 
     
        public void setName(String s)
        {
            name = s;
        }
     
        public String getName()
        {
            return name;
        }
     
        public String toString()
        {
            return name + "   " +  
                    qz1 + "   " + qz2 + "   " +  
                    qz3 + "   " + qz4 + "   " + qz5;
        }
    }

  3. #28
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,845
    My Mood
    Mellow
    Thanks
    239
    Thanked 721 Times in 707 Posts

    Default Re: StudentQuizzesObject

    Uhhhh, what's the question?

Page 2 of 2 FirstFirst 12