Programming Assignment #1
Due: February 13
Deliverables: the .java files
Problem #1 (50 points):
Using Java, design and implement a class called IntArray. The class is an abstract data type that will store integers as an array, but will grow dynamically depending on how many integers are added to it. Implement the following methods:
public class IntArray {
// Adds the int someInt to the end of the IntArray
public void add(int someInt){
}
// Clears all ints from the array, leaving an empty IntArray
// Note: after clear has been called, size() should return 0;
public void clear(){
}
// Given the int someInt, determines if the int is in the IntArray at least once
// Returns true if the int is located, false if it is not in the IntArray
public boolean contains(int someInt){
}
// Given an index, removes the int at that index.
// If index is not in the array bounds, return false.
// If int is successfully removed, return true.
// Note: after a remove, there should be no "blank" spots in the array. In other
// words, the array should "pack" itself so size() returns the correct value;
public boolean remove(int index){
}
// Returns the number of ints in the IntArray
public int size(){
}
// Given the int someInt, returns the index of the first occurrence of someInt
// in the array. Return -1 if someInt is not in the IntArray.
public int getIndex(int someInt){
}
}
The ArrayOfInt class should be dynamic so that ints can always be added, i.e., the number of ints that can be stored increases automatically.
When constructing the IntArray class, you cannot use classes such as ArrayLists, Vectors, etc. You can either use a linked-list of integers, or integer arrays.