SDSU CS 535 Object-Oriented Programming
Spring Semester, 2003
Assignment 3
    Assignment Index        
© 2003, All Rights Reserved, SDSU & Roger Whitney
San Diego State University -- This page last updated 12-Feb-03

Assignment 3

Due: February 18

1. (Corrected 2:15 pm Feb 12, 2003, Class D modified) Assume we have the following class definitions and methods:

Class       A
Superclass       Object
Methods
   name
      ^’A’
   
   foo1
      ^self name
Class       B
Superclass A
Methods
   name
      ^’B’
Class       C
Superclass       B
Methods
   name
      ^’C’
   
   foo2
      ^super name
   
   foo3
      ^self name
   foo4
      ^self foo1
   
   foo5
      ^super foo1
Class       D
Superclass       C
Methods
   name
      ^’D’

Given the following assignments

   exampleC := C new.
   exampleD := D new.
Explain what happens with each of the following expressions:

   exampleC foo1
   exampleC foo2
   exampleD foo2
   exampleC foo3
   exampleD foo3
   exampleD foo4
   exampleD foo5
2. Use a timesRepeat: loop to sum the even integers from 1 to 10.

3. Add a method to the array class to return the maximum element of the array. Assume all elements in the array are of the same type and are subclasses of Magnitude (that is understand <, >, <= ,>=, =).

4. Write a Sunit test for your method in 2.

5. Use select: to create a collection of all even numbers in an array of numbers.

6. Use collect: to convert a string of alphabetic characters to all uppercase.

7. Use inject:into: to find the character with the largest ascii value in a string.

8a. Add a method rot13 to the string class. This method converts all alphabetic characters to lower case. Then it replaces the first 13 characters in the alphabet by the character 13 places forward in the alphabet. It replaces the last 13 characters in the alphabet by the character 13 places backwords in the alphabet. The table below shows how characters are mapped.

8b. Write SUnit tests for your code in 8a.

a
n
b
o
c
p
d
q
e
r
f
s
g
t
h
u
i
v
j
w
k
x
l
y
m
z


Copyright ©, All rights reserved.
2003 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA.
OpenContent license defines the copyright on this document.

    visitors since 11-Feb-03