Computer Science 252
Problem Solving with Java

Fall 2015, The College of Saint Rose

Lecture 21: ArrayList wrapup; Arrays
Date: Tuesday, November 17, 2015


Agenda

Lecture 21 Assignment

Due at the start of class, Thursday, November 19.

Please submit answers to these questions either as a hard copy (typeset or handwritten are OK) or by email to terescoj AT strose.edu by the start of class. Please use a clear subject line when submitting by email (e.g., CSC 252 Lecture 21 Assignment , Joe Student). We will discuss these questions at the start of class, so no late submissions are accepted.

There are a lot of questions here, but most are not especially long. Only the last one will take you some time. Just take your best shot and don't spend a ton of time agonizing over any of them.

  1. Write a method that takes an ArrayList of FilledOval object references as its parameter and returns the count of how many of those FilledOvals are circles. (5 points)
  2. Write instance variable declarations that would declare and construct an array that would hold each of the following. (3 points)

    For example, if asked to construct an array that would store student identification numbers for a class of 100 students, an appropriate answer would be:

        private int[] idNums = new int[100];
    
    1. an array used to hold the populations of the 25 largest cities in New York state
    2. an array used to hold the titles of the chapters of the book Harry Potter and the Half Blood Prince (note: it has 30 chapters)
    3. an array used to hold 7 FilledRects that together form a picture of a picket fence
  3. Convert your program with the stains on t-shirts from a recent in-class exercise to use an array instead of an ArrayList to hold the FilledOvals that represent the stains. This involves changing your instance variable declaration, replacing the construction of the ArrayList with a construction of an array (which much be done after you choose the random number of stains to place on the TShirt), and changing all places that the FilledOvals are added to or accessed within the ArrayList to use the array instead. (10 points)

Terminology

Examples