Computer Science 523
Advanced Programming

Summer 2014, The College of Saint Rose

Lab 4: Collections
Due: 4:30 PM, Tuesday, June 17, 2014

In this week's lab, you will practice with ArrayLists and arrays.

You may work alone or with a partner on this lab. Only one submission per group is needed.

Getting Set Up

To get your BlueJ environment set up for this week's lab assignment, start BlueJ and choose "New Project" from the "Project" menu. Navigate to your folder for this course and choose the name "Lab4" (no spaces) for the project.

Create a document where you will record your answers to the lecture assignment and lab questions. If you use plain text, call it "lab4.txt". If it's a Word document, you can call it whatever you'd like, but when you submit, be sure you convert it to a PDF document "lab4.pdf" before you submit it.

Lecture Assignment Questions

We will usually discuss these questions at the start of class on the lab due date, so no credit can be earned for late submissions of lecture assignment questions.

LA Question 1: Write a method that takes an ArrayList of Integer values as its parameter and returns the sum of all elements in the array. (3 points)

LA Question 2: Gaddis Algorithm Workbench exercise 2, p 532. (1 point)

LA Question 3: Gaddis Algorithm Workbench exercise 3, p 532. (3 points)

LA Question 4: Write a traditional for loop that prints out every element of an ArrayList a. (2 points)

LA Question 5: Write a for-each loop (Gaddis refers to this type of loop as the "enhanced for loop") that prints out every element of an ArrayList a. (2 points)

LA Question 6: Write a short program (or modify an existing example) so that it attempts to get a non-existent element from an ArrayList. For example, if you have an ArrayList of Integer that contains 4 Integer elements, you would attempt to get a value from the array from a position numbered 4 or higher. What happens when you run such a program? (3 points)

Practice Programs

Practice Program: Gaddis Programming Challenge 13, p. 538. Name your program that creates the ArrayList of PhoneBookEntry objects (6 points)

Programming Assignment: Enhancing the CourseGrades Example

Start by making your own copy of the CourseGrades example, and read through the existing code to make sure you understand how it all works. You will be making several enhancements to this program:


Before 4:30 PM, Tuesday, June 17, 2014, submit your lab for grading. There are two things you need to do to complete the submission: (i) Copy your file with the answers to the lecture assignment and lab questions into your project directory. Be sure to use the correct file name. If you prepared your answers in Word, export to a PDF file and submit that. (ii) Upload a copy of your lab (a .7z or .zip file containing your project directory) using Submission Box under assignment "Lab4".


This assignment is worth 70 points, which are distributed as follows:

> FeatureValueScore
Lecture assignment questions 14
PhoneBook practice program 6
CourseGrades average command 5
CourseGrades delete command 5
CourseGrades save command 5
CourseGrades load command 3
CourseGrades merge command 3
CourseGrades stats command (basic) 8
CourseGrades stats command handles ties 3
CourseGrades updates to help command 2
CourseGrades comments 5
CourseGrades naming conventions 2
CourseGrades code organization 2
CourseGrades formatting 1
Lab questions 6
Total 70