December 4, 2022

Smalltalk Exercises - Collections


Clicking on the A graphic will produce the answer.

Question 1
The following creates a set of Chelsea footballers:

blues := Set new.
blues add: 'Ferreira';
      add: 'Terry';
      add: 'Tiago';
      add: 'Lampard';
      add: 'Robben';
      add: 'Carvalho'

A set of Portugese footballers is also created with:

portugal := Set new.
portugal add: 'Costinha ';
         add: 'Ferreira';
         add: 'Rui Costa';
         add: 'Tiago';
         add: 'Figo';
         add: 'Deco';
         add: 'Carvalho'

By using just the two variables and one message in the protocol of Set, write a simple expression that will return a set representing those Portugese footballers that play for Chelsea.

Link to answer for Q1


Question 2
(i) What is the textual representation of this set?
(ii) What is the textual representation of this set when it receives the printString message?

Link to answer for Q2


Question 3
The following code is used to create a set:

mountainSet := Set new.
mountainSet add: 'Matterhorn';
            add: 'Everest';
            add: 'K2'

Explain the consequences of evaluating the following expression:
mountainSet remove: 'Ben Nevis'

Link to answer for Q3


Question 4
Write an expression that will check the set referenced by mountainSet for the presence of the string 'Ben Nevis'. If the string is not present the user is notified by means of a dialogue box.

Link to answer for Q4


Question 5
Write a simple expression that will open dialogue boxes displaying all the elements in mountainSet.

Link to answer for Q5


Question 6
What class of object does deadPoets reference after evaluating the following?

deadPoets := Set new add: 'Milton';
                     add: 'Shakespeare';
                     add: 'Keats'

Link to answer for Q6


Next page » More collection questions

Back to « Iteration exercise
































































Up to top of page