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 or Game Character Overloaded Class from prior assignments, make a copy of the file, and then just add to it for this assignment. 

  1. Student Account or Game Character Overloaded 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 or an inventory for the Game Character.
    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 ones already written.
        2. A new getCourses () or getInventory()
          1. Has no parameters.
          2. Returns an array of all the classes or inventory items.
        3. A new getCourse (int period) or getInventoryItem (int num)
          1. Passes in an integer as the course period or inventory number to know which item in the inventory will be returned.
          2. Hint: array indexing starts at zero, not one.
          3. Returns a string with the class or inventory name for the given number.
      3. Two new Mutator methods (setters)
        1. Keep the seven mutators you already have .
        2. A new setCourses ( String [ ] ) or setInventory( String [ ] )
          1. Passes in an array of new course or inventory names.
          2. Sets courses to the new courses.
          3. Reports the old and new values.
        3. A new setCourse (String, int) or setInventoryItem (String, num)
          1. Passes in two variables
            1. A String as the new course or inventory name.
            2. An integer as the course or inventory number.
          2. Sets the correct name.
          3. Outputs that the information changed from the old to the new information.
      4. A toString method
        1. A normal toString method that outputs everything including the new list of courses or inventory.
        2. You might use an Arras.toString() method to print the classes/inventory or you can write your own code to do this. 
  2. Main Program:
    1. Creates an array of three different 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 or inventory items
      1. You do not have to run the setters nor getters that you imported from the old class. Only run the new setters.
      2. Run the setCourses or setInventory method to modify all of the items for a single student or character. 
      3. Run the setCourse or setInventoryItem method at least once on the other two students. Make sure it works on the first and last item in course/inventory array.
      4. 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

CS Awesome Website

Bill Barnum's AP Computer Science A videos

AP College Board test prep videos