Part I Write the complete class definition or server for Uns
Part I
Write the complete class definition (or server) for UnsortedStringList as described in Chapter 3 of the text.
Part II
Using UnsortedStringList, create a client program that performs the following tasks.
1. Create a list that can hold up to nine planets.
2. Add planets to the list.
3. Delete the first planet inserted into the list.
4. Check to see if Earth is in the list. If so, print \"Earth is in the list\", otherwise print \"Earth is not in the list\".
5. Print the names of all planets in the list.
Solution
import java.util.*;
public class UnsortedStringList {
public static void main(String args[]) {
//Creation of list
ArrayList<String> list = new ArrayList<String>();
//Adding planets to the list
list.add(\"Mercury\");
list.add(\"Venus\");
list.add(\"Earth\");
list.add(\"Mars\");
list.add(\"Jupiter\");
list.add(\"Saturn\");
list.add(\"Urenus\");
list.add(\"Neptune\");
list.add(\"Pluto\");
//Delete 1st element added to list
list.remove(0);
//Check to see if Earth is in the list.
if(list.contains(\"Earth\"))
{
System.out.println(\"Earth is in the list\");
}
else
{
System.out.println(\"Earth is not in the list\");
}
//Print the names of all planets in the list.
System.out.println(\"List : \"+list);
}
}
