2014-11-07 HW

posted Nov 7, 2014, 8:46 AM by Samuel Konstantinovich   [ updated Sep 16, 2015, 8:17 AM ]
SuperArray Lab part 2

Lets agree that: out of range means:
      index < 0  || index >= size()


Now modify the following methods:

Object get(int index) :
      Return the element at the index, if the index is out of rangePRINT an error message, and return null.



Overload add in the following way:
void add() :
      Works the same, but will increase the array capacity if needed.

void add(int index, Object o) :
      Insert the specified element at the specified position in the list. All elements(if any) after the location will be shifted to the right. (Also should increase capacity if needed)
 
Object set(int index, Object o) :
      Place the object at the indeicated location but also: return the Object being replaced, or if the index is out of range PRINT an error message, and return null .



NEW METHODS:

Object remove(int index) :
      Remove the element at the specified index and return that element. The SuperArray should remain left justified. If the index is out of rangePRINT an error message, and return null. 

STOP! THINK: When should remove make the capacity smaller?

You must have a main method that tests to see if all of your methods are correct.

Homework:
1. Make a git repo for your APCSHW. Make a folder in that repo called 01SuperArray and put your SuperArray code there.

2. On the homework server, submit a comment with your git Homework repo. 
Comments