Escolar Documentos
Profissional Documentos
Cultura Documentos
Part 1 (A: 1 marks for each , B: 2 marks for each) Total of 60 marks
FORM A
Internet: a system that has both hardware and software components, which
allow data to be exchanged and processing tasks to be distributed.
ANS:
a. x1 := toad1 position.
x2 := x1 + 5.
toad2 position: x2
b. account2 balance: (account1 balance) + 500
Q3. For each of the following message expressions, write down the required information. Note
that frog1 is in its initial state.(position -->1, colour -->Green)
ANS:
a. The receiver: frog1
The message: position
The message selector: position
The argument (s):No arguments
The message answer: 1
The texual representation of the message answer: 1
b. The receiver object evaluated to: false
The message: ifFalse:[frog1 brown. frog1 left]
The message selector: ifFalse:
The argument: [frog1 brown. frog1 left] or Block object
The message answer: frog1
The texual representation of the message answer: An instance of class Frog (position 0,
colour Brown)
c. The receiver: Dialog
The message: warn:'Good luck'
The message selector: warn:
The argument (s):'Good luck'
The message answer: nil
The texual representation of the message answer: nil
Q4. Given the following expression series:
| x y |
x := 1.
y := 9.
[y >= 3] whileTrue:[x := x + y.
y := y - 3]
ANS:
(a) x = 10, y = 6.
(b) x = 19, y = 0.
Q5- Draw the class hierarchy diagram that represents the relation between the Shape,
Rectangle, Circle, Square, Four_edged_shape. The Four_edged_shape is a template
class for objects of shapes that have four edges.
Ans:
Shape
Four_edged_shape Circle
Square Rectangle
Q6: ANS:
Affordance: The degree to which it is obvious to the user how to operate the control.
A key principle of HCI that states that the appearance of any control should
suggest its functionality.
Usability: How easy a system is to learn and use.
ANS:
(a)
abstract class: This is a class which should never have instances, rather it is used to specify
the minimum set of messages to which any subclass (of the abstract class) can
respond.
An abstract class describes the common characteristics of its subclasses.
Example: Amphibian, Object, Magnitude, Number, Integer,...
concrete class A class of which instances are created.
Example: Frog, Toad, HoverFrog, Account, SmallInteger, ...
(b)
There are 3 concrete classes to represent integers.
Reason: efficiency of speed of execution and of memory usage .
Q8. (a) Briefly explain the difference between abstract methods and base methods giving one
example on each one.
ANS:
(a)
Abstract A method which does not implement the required behaviour and requires the
method: subclasses to provide their own implementations by overriding the abstract
method. An abstract method will normally contain the code ^self
subclassResponsibility.
Example: home and left in the class Amphibian and the methods < and = in the
class Magnitude
Base method A method which is fully implemented in the abstract class and can be
inherited and used in subclasses as it stands.
Example: brown, green, colour, colour:, position, position: in the
abstract class Amphibian.
(b)
Instance Instance variables can only be directly accessed from the methods of the
variables: class in which they are defined and from the methods of its subclasses.
Class variables are visible to and can be used directly by the class and
Class variables: instance methods of the class, its subclasses, instances of the class and
instances of any subclasses.
Part 3: (total of 42 marks, two questions to be selected, 21 marks for
each question)
Question 1.
ANS:
a.
Question 2. (a) Quizzes grades for three students are to be stored in arrays of numbers. Write an
expression series to create three arrays: student1Quizzes, student2Quizzes &
student3Quizzes), each consists of three elements. Then use at:put: (or any other
way you've learned) to add the data of the 3 quizzes in the corresponding array according to
the table below:
ANS:
(a) student1Quizzes := Array new: 3.
student1Quizzes at: 1 put: 80; at: 2 put: 90; at: 3 put:
77.
student2Quizzes := Array new: 3.
student2Quizzes at: 1 put: 95; at: 2 put: 95; at: 3 put:
99.
student3Quizzes := Array new: 3.
student3Quizzes at: 1 put: 72; at: 2 put: 60; at: 3 put:
55.
OR:
student1Quizzes := #(80 90 77).
student2Quizzes := #(95 95 99).
student3Quizzes := #(72 60 55).
(b) studentDictionary := Dictionary new.
studentDictionary
at: 'Ahmad' put: student1Quizzes;
at: 'Omar' put: student2Quizzes;
at: 'Sami' put: student3Quizzes
Ans:
1. (8 marks, 2 marks for each)
a. In the first line, aliens should be Aliens (with capital letter) as the class
name in the variable reference diagram appears.
b. In the first line, new should be after Aliens not before it.
c. In the third line, “.” Is missing.
d. In the last line, the keyword message selector concatenate: lacks its
colon “:” in the forth line.
score:= Dialog request: ‘Enter the student’’s final score please (0-100)’.
score:= score asNumber.
(score >= 90) ifTrue: [ grade:= ‘A’. ^grade]
ifFalse: [(score >= 80) ifTrue:[ grade:= ‘B’. ^grade]
ifFalse:[(score >= 70) ifTrue: [grade:= ‘C’.
^grade] ifFalse: [(score >= 60) ifTrue: [grade:= ‘D’.
^grade] ifFalse:[grade:= ‘F’. ^grade]]]].