Allan Didier

Student Account Array


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.


  • Arrays of objects

Program Details

Create a program that can create, access and modify an array of student accounts from a student account class. You can use your Student Account Class from the prior assignment, make a copy of the file, and then just add to it for this assignment. 

  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 seven mutators you already have (setName x2, setAddress x2, setGradYear x3).
        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 course 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. It should call the classesToString method below to print the list of 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.
  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 initial and final student values using the toString method.


Java Textbook

Chapter 8: Arrays

Bill Barnum's AP Computer Science A videos

AP College Board test prep videos