List Exercise

Name:  ______________________________________________________________________

1. Unordered Lists

Complete the class below which maintains an unordered array of integers. Be sure to fill in the code for the main method.
```
/**
* Uses an array to maintain an unordered list of numbers.
* New numbers are added to the end of the list.
* The first instance of a given number is removed from the list
*/
public class UnorderedList {

private final int DEFAULT_SIZE = 10;  //default size of list
private int numberOfItems;            //number of items currently in list
private int[] numbers;                //array of values

//Default constructor
public UnorderedList()  {             //Creates a list with room for 10 values

}
//Constructor
public UnorderedList(int listSize)  { //Creates a list with room for
//listSize values

}

public void addToEnd(int number) {   //Add number to the end of the list

}

public void removeNumber(int number) {  //Remove the first occurrence of number
//in the list, do nothing if number is
//not in list

}

public String toString() {     // Returns a String in the format:
// [1, 89, 23, 34]   (note there is no comma after
// the last number). If the list is empty the
// String should be: []

}

public static void main(String args[]) {

//Create an UnorderedList named
//myList with room for 5 numbers

//Output myList

//Remove a number from myList

//Output myList

//Use the "default constructor" to
//create an UnorderedList named
//otherList

//Add the numbers 1 - 10 to
//otherList

//Output otherList

//Remove the numbers 1 - 10 from
//otherList

}

```

2. Ordered Lists

Complete the class below which maintains an ordered array of integers. Be sure to fill in the code for the main method.
```
/**
* Uses an array to maintain an ordered list of numbers.
* New numbers are inserted so that each number in the list is
* less than or equal to the number that follows it in the list.
* The first instance of a given number is removed from the list.
*/
public class OrderedList {

private final int DEFAULT_SIZE = 10;  //default size of list
private int numberOfItems;            //number of items currently in list
private int[] numbers;                //array of values

public OrderedList()  {             //Creates a list with room for 10 values

}

public OrderedList(int listSize)  { //Creates a list with room for
//listSize values

}

public void insertNumber(int number) {   //Insert number in the correct position
//in the list

}

public void removeNumber(int number) {  //Remove the first occurrence of number
//in the list, do nothing if not in list

}

public String toString() {     // Returns a String in the format:
// [1, 89, 23, 34]   (note there is no comma after
// the last number). If the list is empty the
// String should be: []

}

public static void main(String args[]) {

//Create an OrderedList named myList
//with room for 5 numbers

//Output myList

//Remove a number from myList

//Output myList

}
}

```

3. Ordered Lists of Class References

Complete the Student class below which has a name and a integer age as data:
```

public class Student {

public Student(String name, int age) {

}

public String getName() {    //Returns the name of the Student

}

public int getAge() {        //Returns the age of the Student

}
}

```
Complete the class below which maintains an ordered array of Student class references. The Student's are ordered by increasing age. Be sure to fill in the code for the main method.
```
/**
* Uses an array to maintain an list of references to
* Student class objects.
* New Student's  are inserted so that the age of
* each Student in the list is less than or equal to the age
* of the Student that follows it in the list.
* The first instance of a given Student is removed from the list.
*/
public class StudentList {

private final int DEFAULT_SIZE = 10; //default size of list
private int numberOfStudents;        //number of students currently in list
private Student[] students;          //array of references to Student class objects

public StudentList()  {          //Creates a list with room for 10 students

}

public StudentList(int listSize)  { //Creates a list with room for
//listSize students

}

public void insertStudent(Student student) {  //Insert Student in the correct
//position in the list depending
//on age of student

}

public void removeStudent(String name, int age) {  //Remove the first occurrence
//of a student in the list
//with the given name and age
// Do nothing if not in list

}

public String toString() {     // Returns a String in the format:
// Bob, 12
// Tom, 15
// Mary, 18
// Joe, 19

}

public static void main(String args[]) {

//Create a StudentList named myList
//with room for 5 students

//Add the students listed above to myList

//Output myList

//Remove Joe from myList

//Output myList
}
}

```