Validated by Amaya

Richard G Baldwin (512) 223-4758, NRG Room 4238, Baldwin@DickBaldwin.com, http://www.austincc.edu/baldwin

INEW 2338 Advanced Java Programming

Assignment 8 - Collections - Chapter 11

Revised 01/09/10 for Amaya compatibility

The files that you deliver for this assignment must include a controlling class file named Asg08.class plus all of the source code files that you compiled to produce your class files.

Click here for general requirements regarding all programming assignments. 

Click here to download a zip file containing a sample version of this assignment.  Your application must replicate the look, feel, and behavior of this sample except that your name must be included in the output of your version of the application where indicated.

Before you start writing this assignment, you should study the study guide entitled Collections.

Write the Java application described below.

I will compile the class named Asg08 shown in Listing 1 and will copy the resulting file named Asg08.class into a folder containing a file that you must provide named Asg08StudentClass.class(You must also provide the source code that you compile to produce that class file.)

If your folder contains a file named Asg08.class, it will be overwritten by my class file having the same name.

When my file named Asg08.class is executed, in combination with your file named Asg08StudentClass.class the program must behave as described below.

The two class files working together must produce a screen output consisting of five lines of text similar to that shown in Listing 2.

In other words, the output displays the date and time for three consecutive days, beginning with the date and time that the program is executed, in the order described above.

To guard against runtime errors when the two class files created at different times are combined, you should use the following method signatures for those methods in your class that are invoked by code in my class.

public boolean add(Object o)

public Iterator iterator()

import java.util.*;
class Asg08{
  public static void main(String[] args){
    System.out.println("Asg08");
    Collection var = new Asg08StudentClass();
    long oneDay = 24*60*60*1000;
    long now = new Date().getTime();
    var.add(new Date(now + 2*oneDay));
    var.add(new Date(now + 2*oneDay));
    var.add(new Date(now + oneDay));
    var.add(new Date(now + oneDay));
    var.add(new Date(now));
    var.add(new Date(now));

    Iterator iter = var.iterator();
    while(iter.hasNext()){
      System.out.println(iter.next());
    }//end while loop
    System.out.println();
  }//end main
}//end class Exam1Asg08
//End program specifications

Listing 1

 

Asg08
Put your name here
Thu Oct 21 12:21:52 CDT 2004
Fri Oct 22 12:21:52 CDT 2004
Sat Oct 23 12:21:52 CDT 2004

Listing 2

-end-

File:  Asg08.htm