No collaboration is allowed on this program assignment. Your program must be an individual and original effort. Except for any situations explicitly identified in this assignment, if any, you may only receive help from your instructor or the tutors provided by the Computer Science Department. See the Syllabus for the significant consequences for disallowed collaboration and/or plagiarism.
ErrataSubmit the following file(s) on one of the CSL servers using handin as follows:
File(s): BasicList.java BasicArrayList.java
touser: eaugusti
assignment/subdirectory: 102-program02b
ObjectivesYou will
be implementing a class that represents a simple list like, for
instance, a list of numbers, a shopping list, or a todo list. Common
things one does with a list include adding stuff, removing stuff,
seeing if somthing is on a list. In programming lingo, a list is an
example of an Abstract Data Type (ADT). An ADT is a data type whose
logical operations are defined independently of the physical (concrete)
implementation. As you know, a Java interface specfies method
signatures but no method logic - an excellent choice for defining an
ADT! You will implement the methods specified by the interface (plus a
few more) using an array of Object references to support the list
operations. Later in the quarter you will implement that same ADT a
completely different physical implementation to experience, once again,
how the logic associated with a methods can be achieved in different
ways.
Your source code must meet the Coding Style Guidelines.
Do not suppress any compiler warnings. If you do, your submission may be rejected for grading or your grade marked down at your instructor's descretion.
You may implement any private methods you wish to make your implementation easier and/or better.
Write a Java interface called BasicList to this specification.
Be sure to read the detailed method descriptions as there is often addtional and necessary information there.
Write a Java class called BasicArrayList to this specification. This class is not a generic class like the Java Standard Library's ArrayList class. Instead, it will be built upon a array of Object references. Remember, due to polymorphism, a reference to any object of any type is also an instanceof Object. This means your BasicArrayList class can store a reference to any and all Java class types - even ones that have not even been written yet!
Be sure to read the detailed method descriptions as there is often addtional and necessary information there.
This class must be written using an array of Object references to store and retrieve values.
In the spirit of minimal necessary instance variables, your class is limited to two instance variables, an Object[] to hold references to the items added to the list and an int to keep track of the number of items in the list (its size). Be sure you don't confuse the size of a list with its capacity.
You must only allocate a new array when it is necessary to grow or shrink the capacity of the array.
Recall that arrays are fixed in size. For any method that increases the size of the array (adds stuff) you must grow the private array, as and when necessary, to support the operation. When attempting to add to an array that is full you must make a new, larger array, copy all the old arrays stuff into it, and add the new element. You must use this algorithm when growing the array - the new larger array must always be exactly twice as large as the old (full) array.
Several of the methods in this class throw exception when certain errors occur. Be sure to read the detailed method descriptions to see which methods and what specific exceptions. You will have to write the conditional logic to determine when to throw the exceptions. Exceptions are Java classes - just contstruct the type you want to throw and throw it. Here is an example of how to throw an IndexOutOfBoundsException (don't forget that you may need to import the exception if it is not in java.lang):
Do not use the provided test driver until your solution is complete and you believe it is correct.
Using the save-as
feature of your browser, not
cut-and-paste, save P2bTestDriver.java
(to be published on the first due date) in the same directory as all of
the source files (.java files).
Compile the P2bTestDriver.java, all of your source files (.java files), and run P2bTestDriver (see How to Compile and Run From the Command Line, as necessary). Remember that your code will be graded on one of the CSL servers so, to avoid unpleasant grading surprises, be sure to test on any one of those machines at least once after all changes and just before handing in!