AP CS Assignments
Assignments by week:
Fall Term:
Winter Term:
Spring Term:
Thursday, January 3
Description
Welcome Back to ADTs
Homework
  • Today we started talking about Abstract Data Types and how there is the abstract definition and the actual concrete implementation. You're going to write the implementation for the List ADT. A List is like an array, except that grows to accomodate data that are added to it. There is an add() method that appends data to the end of the list, and this can be called without limit. Because the class is not a true array, you must use methods like get(int) to access the list, instead of array notation like a[int].

    Read Section 9.2 - List ADT in DSA. Section 9.3 is also helpful as it discusses implementation, but it is optional as it will differ slightly from our APCS List implementation below so you'll still need to think carefully when writing your own if you read that section!

    Download the ArrayList lab zip file. Complete the class called ArrayList so that implements the AP List interface using an array as its means of storage. You must implement all of the required methods of the interface except iterator() and listIterator() (you may just return null for those methods). You are also welcome to write additional private helper methods if you wish. Complete the required methods by the start of next class (the final complete version will be due Tuesday, but we'll start with this).

    Hint: we're working with generics, but Java does not allow the direct creation of arrays with a generic type. To make a generic array, you should create an Object array and then cast it to the generic array type, like this:

    @SuppressWarnings("unchecked")
    E[] newArray = (E[])new Object[10];
      
Friday, January 4
Description
Java Generics
Homework
  • Read the following article on Iterating over collections in Java 8. It provides some good background and history on how Java approaches iteration. The second page of the article (Java 8 Streams) is interesting with regards to "real" I/O, but will not be used or tested in class. If it's tricky you can skim it and focus on the first half of the article.
  • Continue working on your ArrayList ADT class. We'll cover the iterator stuff during the next class, but you should have the rest of it fully written so you don't fall behind.