class UseLinkedList { public static void main(String[] args) { LinkedList names = new LinkedList(); String name = ""; // Good insert at head of list try { names.insert(0, new String("Scott")); } catch(Exception e) { System.out.println(e); } // Good insert at head of list try { names.insert(0, new String("Haley")); } catch(Exception e) { System.out.println(e); } // Good insert in middle of list try { names.insert(1, new String("Michelle")); } catch(Exception e) { System.out.println(e); } // Good insert at end of list try { names.insert(3, new String("Cory")); } catch(Exception e) { System.out.println(e); } // Bad Insert, off the end of the list try { names.insert(7, new String("Scott")); } catch(Exception e) { System.out.println(e); } // Print out the list System.out.println("\nHere's the list:"); for(int i = 0; i < names.length(); i++) { try { name = (String)names.get(i); } catch (Exception e) { System.out.println("Exception: " + e); } System.out.println(" Item " + i + ": " + name); } // Delete the first item try { names.delete(0); } catch(Exception e) { System.out.println(e); } // Delete the last item try { names.delete(2); } catch(Exception e) { System.out.println(e); } // Bad delete, off the end try { names.delete(7); } catch(Exception e) { System.out.println(e); } System.out.println("\nHere's the modified list:"); for(int i = 0; i < names.length(); i++) { try { name = (String)names.get(i); } catch (Exception e) { System.out.println("Exception: " + e); } System.out.println(" Item " + i + ": " + name); } } }