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
- Announcements
- Lab 12: ArrayList Practice due Thursday night
- Exam 3 in one week
- same ground rules as Exam 1 - closed book, closed
notes, closed network, closed neighbors, but relevant
portions of the reference card will be provided
- topic focus is on those since the first exam, but of
course the material is cumulative by nature: active objects,
Java interfaces, Java Swing GUI, Recursion, ArrayLists.
Note that our new topic of arrays is not covered.
- optional review session Friday, 2:30-3:30, Location TBD
- practice exam questions out
- Lab 10: Final Project design phase is
underway, designs will be accepted without late penalty until you
leave for break, but you are encouraged to do them sooner
- Exam 2 Lab Practical recap
- In-class Exercise 21 - (15 lecture assignment
points) due before the end of class.
We will work together to develop a Java application that includes a
few methods that use ArrayLists. Methods will include
- the one we
saw previously to find the sum of an ArrayList of Integer
- one that takes a second int parameter in addition to the
ArrayList and returns another ArrayList of Boolean
where each entry indicates whether the corresponding entry in the
original ArrayList is evenly divisible by the given int
- one that returns whether the input ArrayList has any zero
values.
Please demonstrate your program or
submit only the file
ArrayListPractice.java by email before you leave class. Email submissions should use a meaningful
subject line, clearly indicating the course number and assignment
name.
- Introduction to arrays
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.
- 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)
- 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];
- an array used to hold the populations of the 25 largest
cities in New York state
- 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)
- an array used to hold 7 FilledRects that together form
a picture of a picket fence
- 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