Lab07 Hints and Tips

Part 0 -- Using an ArrayList

Please do this part before doing the Part 1 in the Lab guide.

  1. Create a new Java project named Lab07Extra.
  2. Create a new package in the project named logic, then copy the classes in the logic package from the Lab03 project to the new package.
  3. Create a new class named TestCustomer in the test package with a main method.
  4. Complete main as follows:
    1. Create an ArrayList collection using its zero-argument constructor:
      ArrayList<Customer> myList = new ArrayList<>();
      			
    2. Create a few Customer objects and store them in the ArrayList. To add the first Customer, your code might look something like:
      Customer c1 = new Customer("Slim", "Dunlap", "K", "Jr.");			
      myList.add(c1);			
        			  
    3. Write an iteration loop using the enhanced for loop that retrieves each Customer from the ArrayList and prints its reference to the console. Use the code on page 8-12 in the course notes as a guide, but note that your collection contains Customer object references instead of Integer object references.
  5. Run and test your program.

Part 1

Part 2