Computer Science 252
Problem Solving with Java
Spring 2016, The College of Saint Rose
Lecture 21: Arrays
Date: Tuesday, April 12, 2016
Agenda
- Announcements
- Lab 10: Final Project proposals due later this week
- Lab 11: Recursion Practice now on the late clock
- Lab 12: ArrayList Practice underway
- 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 likely Monday 4 PM, Location TBD
- practice exam questions out
- Recap of in-class exercises from last time
- Lecture 20 assignment 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, April 14.
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, Mary Smith). 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 a method that takes an ArrayList of FilledOval
object references as its parameter and returns an ArrayList of
Boolean where each entry contains a value indicating whether
the value at the corresponding index in the input ArrayList
represents a circle. (5 points)
For example, if the dimensions of the FilledOvals in the input
are 54×12, 98 ×98, and 123 ×123, the returned
ArrayList should contain three Boolean objects, the first of
which encapsulates the value false, and the second and third
encapsulate the value true.
- 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
Terminology
Examples