Home CPSC 340

Lab 3: Making an ArrayList

 

Objective

To get experience using generic classes, and begin an implementation of a generic ArrayList.


 

Task

For this lab you will begin working on re-creating the ArrayList class in Java. You will write some of the things we will need, and we will continue it in class.


 

Details


 

Testing

You can test your code with the following main class:

 
public class ArrayTest {
    public static void main(String args[]) {
        DynamicList<String> names = new DynamicList<String>(15);

        names.add("Alice");
        names.add("Billy");
        names.add("Claire");
        names.add("Donovan");
        names.add("Ethel");
        names.add("Frank");
        names.add("Gina");
        names.add("Hank");
        names.add("Ima");
        names.add("Joel");
        names.add("Kathy");
        names.add("Leon");
        names.add("Marion");
        names.add("Neville");
        names.add("Ophelia");
        
        for (int i = 0; i < names.size(); i++) {
            System.out.println(names.get(i));
        }

        names.clear();
        for (int i = 0; i < names.size(); i++) {
            System.out.println(names.get(i));
        }
    }
}

This code should then produce the following output:

Alice
Billy
Claire
Donovan
Ethel
Frank
Gina
Hank
Ima
Joel
Kathy
Leon
Marion
Neville
Ophelia

 

Submitting

When you are finished, please email me your .java file at ifinlay@umw.edu.

Copyright © 2019 Ian Finlayson | Licensed under a Creative Commons Attribution 4.0 International License.