Allan Didier

Student Account Array

Goals

Students will demonstrate their understanding of arrays, object instantiation, class creation and the use of constructor, accessor, and mutator methods in Java by modifying their student account program following the details below.

Skills

  • Arrays of objects

Program Details

Create a program that can create, access and modify an array of student accounts from a student account class.

  1. Student Account Class
    1. One new private Data Variable
      1. Keep the others the same (name, address, and graduation year)
      2. A String array of 7 course names that the student is taking.
    2. Methods
      1. Two Constructors methods
        1. One with no parameters and asks the user to enter the data.
          1. Modify this so that the user also enters the class names.
        2. One that sets all variables by directly passing the values in directly as parameters.
          1. You can pass the array values in individually or as an array. You choose which is easier for you.
      2. Two new Accessor methods (getters)
        1. Keep the three already written (getName, getAddress, getGradYear).
        2. A new getCourses ()
          1. Has no parameters.
          2. Returns an array of all the classes.
        3. A new getCourse (int period)
          1. Passes in an integer as the course period to know which course will be returned.
          2. Hint: array indexing starts at zero, not one.
          3. Returns a string with the class name for the given period.
      3. Two new Mutator methods (setters)
        1. Keep the sevn mutators you already have (setName x2, setAddress x2, setGradYearx2).
        2. A new setCourses (String [] newcourses)
          1. Passes in an array of new course names.
          2. Sets courses to the new courses.
          3. Outputs that student’s old courses have changed to the new courses. Output the old and new couse names.
        3. A new setCourse (String newname, int period)
          1. Passes in two variables
            1. A String as the new course name.
            2. An integer as the course period.
          2. Sets the correct course to the new name.
          3. Outputs that the student’s course name has been changed from the old name to the new name.
      4. Two toString methods
        1. a normal toString method that outputs everything: name, address, grad year and  all of the classes.
        2. a classesToString method
          1. turns the array of classes into a string.
          2. runs through a for loop to create this string.
          3. returns a string of all classes.
        3. Outputs all of the account information including the courses in a clean and readable format.

  2. Main Program:
    1. Creates an array of three different student objects
      1. One is initialized with one constructor,
      2. One is initialized using other constructor.
      3. The third can be initialized either way.
    2. Modify the student classes
      1. You do not have to modify the student names, addresses, nor graduation years.
      2. Modify all of the first student’s classes with the setCourses method.
        1. Your main program will have to create an array of course names and pass it in.
      3. Modify only the 1st and 7th period classes of the second student.
      4. Modify only the 4th period class of the third student.
      5. Each setter method should output that the values have changed.
    3. Output the final student values using the toString method.

Resources

Edhesive Term 1

Lesson 28: Arrays of objects

Lesson 29: Array of objects methods