MIT | MIT-AITI | Ethiopia 2004

Java Lab 6: Object Oriented Gradebook - Part II

  1. Add appropriate access modifiers to all your fields and methods in GradebookOO and GBProgram. Compile.
  2. Add a method to GradebookOO called addGrade which accepts a double argument and adds it to the array of grades. This is difficult. Two things you should note:
    • arrays always have the same length, so you can't increase it the size of it
    • arrays are objects not primitives, so variables of type array hold references to arrays
    Here are the steps your addGrade method should follow:
    1. When addGrade is called, the grades field holds a reference to an array of grades:
      	grades ���> [83.2, 97.4, 76.8]
      
    2. Create a new array, maybe call it temp, that is a size 1 bigger than grades:
      	grades ���> [83.2, 97.4, 76.8]
      	  temp ���> [    ,     ,     ,     ]
      
    3. Copy over all the elements from grades into temp:
      	grades ���> [83.2, 97.4, 76.8]
      	  temp ���> [83.2, 97.4, 76.8,     ]
      
    4. Add the new grade into the last slot of temp:
      	grades ���> [83.2, 97.4, 76.8]
      	  temp ���> [83.2, 97.4, 76.8, 90.5]
      
    5. Change grades so it points to the temp array:
      	grades ���> [83.2, 97.4, 76.8, 90.5]
      
  3. Delete the GradebookOO constructor that takes an array of doubles as an argument. And change the main method of GBProgram so that it instantiates an empty GradebookOO and adds the grades one-by-one to it with the addGrade method. Compile and run.
  4. (Optional) If you have not done so in the past few labs, use EasyReader to read the grades from the user and print out a menu to the user. See Steps 3 and 4 of Lab 4 for more details.
  5. (Optional) Add a method deleteGrade to GradebookOO which accepts a grade as an argument and removes it from the array if it is there. This is tricky. Compile and run.

Submission: Submit all of your code for this lab.

Hosted by www.Geocities.ws

1