COP 2800 (Java Programming I) Homework Assignment #6

 

Due: by the start of class on the date shown on the syllabus

Description:

Answer the following questions as briefly (but completely) as possible:

  1. How do you create a Date for the current time?  How do you display the current time?
  2. How do you do the following tasks?
    1. Create an ArrayList for storing double values?
    2. Append an object to a List?
    3. Insert an object at the beginning of a List?
    4. Find the number of objects in a List?
    5. Remove a given object from a List?
    6. Remove the last object from a List?
    7. Check whether a given object is in a List?
    8. Retrieve an object at a specified index from a List?
  3. Identify the errors in the following code fragment:
    ArrayList<String> list = new ArrayList<String>();
    list.add( "Denver" );
    list.add( "Austin" );
    list.add( new java.util.Date() );
    String city = list.get( 0 );
    list.set( 3, "Dallas" );
    System.out.println( list.get(3) );
  4. Suppose the ArrayList list contains duplicate elements.  Does the following code correctly remove all elements from list?  If not, correct the code.
    for ( int i = 0; i < list.size(); i++ )
       list.remove( element );
  5. Explain why the following code fragment displays [1, 3] rather than [2, 3].
    ArrayList<Integer> list = new ArrayList<Integer>();
    list.add(1);
    list.add(2);
    list.add(3);
    list.remove(1);
    System.out.println( list );
  6. How do you create a Calendar object for the current time?
  7. For a Calendar object c, how do you get its year, month, date, hour, minute, and second?

To be turned in:

Email your homework assignment, by copy-and-paste (no attachments please), to (homework submission).  If possible use the “text” and not the “HTML” mode of your email program.  Please use the subject similar to “Java Programming I Homework Assignment #6 Submission”, so I can tell which emails are submitted homework assignments.

Homework assignments will not be returned.  Please do not send as attachments.  Refer to the Homework and the Submitting Assignments sections of your syllabus for more information.

Confused?  Send questions about the homework assignment to (homework questions).  Please use a subject similar to “Java Programming I Homework Assignment #6 Questions” so I can tell which emails are questions about assignment quiz (and not submissions).