Lab 4

Due Friday 3/2 - 5:00pm

    1. For this question, you will implement your own version of ArrayList. Your class, called StringList, will maintain an array of Strings and provide most of the functionality of the ArrayList. In particular, you must implement the following components in your StringList class:
      1. A data member of type String[] that will maintain a list of String objects.
      2. A data member of type int that will keep track of the number of items that have been added to the list.
      3. A constructor that takes no input and will instantiate a new String[] of size 10.
      4. A constructor that takes as input the size of a new String[] and will instantiate a new array of that size.
      5. The following methods that behave exactly as specified in the ArrayList documentation:
      6. public boolean add(String s) - adds the new item s to the end of the array and returns true, in case the array is full, it will be resized by creating new array of twice the size and copying all elements
      7. public void add(int index, String s) - adds the new item to the array at the location specified by index, in case the array is full, it will be resized by creating new array of twice the size and copying all elements
      8. public boolean contains(String s) - returns true if the array contains the string s
      9. public boolean isEmpty() - returns true if there are no elements in the array
      10. public int size() - returns the number of elements in the array
      11. public int indexOf(String s) - returns the first index of the given String, returns -1 if not found
      12. public int lastIndexOf(String s) - returns the last index of the given String, returns -1 if not found
      13. public String get(int index) - returns the String at the given index, may throw IndexOutOfBounds exception
      14. public String set(int index, String s) - replaces the element at index with the given string, may throw IndexOutOfBounds exception, returns the item replaced
      15. public String remove(int index) - removes the item at the given index and returns it, may throw IndexOutOfBounds exception
      16. public boolean remove(String s) - removes the given item, returns true if successful
      17. public String toString() - returns a string representation of the array
    2. Your grade will partially depend on whether the tests outlined in StringListTester pass when using your StringList class.
  1. For this question, you will get a start on Project 2. The next project will require you to manipulate an image by altering the RGB values for each pixel. (This question and the project are modified from an assignment specified by Richard Wicentowski and Tia Newhall of Swarthmore.) It is highly recommended that you read the Project 2 description carefully before beginning this question. First, download Picture.java and Pixel.java (courtesy of Wicentowski and Newhall). This bit of code will give you a starting point for reading an image from a file. You can create a new Picture object, passing in a file name. Make sure to use a gif image file. You can then access individual pixels of the image represented by the object. You will then create a class ImageManipulator with the following properties. You will also create a driver that creates an instance of ImageManipulator and invokes the methods described below.
    1. A data member of type String to hold the name of the file.
    2. A data member of type Picture to hold the image.
    3. A constructor that takes as input a filename, sets the file name data member, and creates a new Picture object using the filename.
    4. A method makeNegative that takes no input. The method will create an inversion of the original image by setting the red value for each pixel to be 255 minus the original red value, and the same for green and blue. The new image will be saved to a file called negative.gif.
    5. A method flipVertical that takes no input. The method will flip the image along the vertical axis, effectively turning it upside down. The new image will be saved to a file called verticalflip.gif.

Submission

Please submit your work in an SVN directory https://www.cs.usfca.edu/svn/<username>/cs112/lab4.

Submission Instructions