Java Software Structures, 4th Edition Exercise Solutions, Ch. 7
Chapter 7 Exercise Solutions
EX 7.1 Write a for-each loop that prints all elements in a collection of Student objects
called role. What is required for that loop to work?
for (Student pupil : role)
EX 7.2 Write a while loop that uses an explicit iterator to accomplish the same thing as
Exercise 7.1.
Iterator<Student> itr = role.iterator();
EX 7.3 Write a for-each loop that calls the addInterest method on each BankAccount
object in a collection called accounts. What is required for that loop to work?
for (BankAccount accnt : accounts)
EX 7.4 Write a while loop that uses an explicit iterator to accomplish the same thing as
Exercise 7.3.
Iterator<BankAccount> itr = accounts.iterator();