Homework #3 Assignment (demonstration due by noon Monday 3/28)

This assignment is very similar to Homework #2, except that you will completing only the following methods of the DoublyLinkedList class (the italic methods were done during lecture):

add(E element)
add(int index, E element)
clear()

contains(E o)
get(int index)
isEmpty()
remove(int index)
set(int index, E element)
size()

Demonstrate and Submit (via Blackboard) your DoublyLinkedList.java file to me in order to receive credit.

To test your implementation, use the same program as last time, except that you substitute DoublyLinkedList for ArrayWrapper:

import java.util.List;

public class HW3App {

	public static void main(String[] args) {

		List<Person> x = new DoublyLinkedList<Person>();
		System.out.println("IsEmpty: " + x.isEmpty()); // should print "true"

		Person ann = new Person("Ann", 18, 100);
		x.add(ann);
		Person bob = new Person("Bob", 19, 101);
		x.add(bob);
		Person carl = new Person("Carl", 18, 102);
		x.add(carl);
		for(int i=0; i<x.size() ; i++) {
			System.out.println(x.get(i).toString() );
		}
		System.out.println("IsEmpty: " + x.isEmpty()); // should print "false"

		Person dave = new Person("Dave", 19, 103);
		x.add(1, dave);
		for(int i=0; i<x.size() ; i++) {
			System.out.println(x.get(i).toString() );
		}

		System.out.println("Contains dave: " + x.contains(dave)); // should print "true"

		Person ed = new Person("Ed", 19, 104);
		System.out.println("Contains ed: " + x.contains(ed)); // should print "false"
		
		x.remove(2); // remove bob
		
		for(int i=0; i<x.size() ; i++) {
			System.out.println(x.get(i).toString() );
		}
		
		System.out.println("Size="+ x.size() );
		x.clear();
		System.out.println("IsEmpty: " + x.isEmpty()); // should print "true"
		System.out.println("Size="+ x.size() );
	}	
}

The test program should generate the same output as before (shown below):

IsEmpty: true
Ann, age=18, id=100
Bob, age=19, id=101
Carl, age=18, id=102
IsEmpty: false
Ann, age=18, id=100
Dave, age=19, id=103
Bob, age=19, id=101
Carl, age=18, id=102
Contains dave: true
Contains ed: false
Ann, age=18, id=100
Dave, age=19, id=103
Carl, age=18, id=102
Size=3
IsEmpty: true
Size=0