CS 535 Object-Oriented Programming and Design

Fall Semester, 2008

Assignment 3

Assignment Index

© 2008, All Rights Reserved, SDSU & Roger Whitney

 San Diego State University -- This page last updated 9/17/08

Due Sept 30

1a. Add a method to the Array class to return the average of all the odd numbers in the array. Assume all elements in the array are Numbers. So #( 1 5.3 4 5  3)  would result in the average 3.

1b. Write a Sunit test(s) for your method in part a.

2a. Use select: to create a collection containing all the characters in a string that have an ascii value higher than the ascii value of k and less than w.

2b. Use collect: to compute the square of each number of a collection .

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

3. Words. Add a method called words to the String class. This method returns a collection of the words in a string. For this problem words are separated by one or more of the following characters: space, tab, carriage return, period (.), comma (,) , semicolon (;), question mark (?),  or the exclamation point (!). Provide Sunit test(s) for the method. (Hint see the method tokensBasedOn: or runsFailing:do:)


4. For this problem the value of an alphabetic character is its location in the alphabet. So ‘a’ and ‘A’ each have value 1, ‘b’ and ‘B’ each have 2, etc. Non-alphabetic characters can be considered to have value 0. The value of a word is the sum of the value of all its characters. So ‘Smalltalk’ has value 101 and ‘cat’ has value 24. A dollar word is a word whose value is 100.  Add a method to the String class that returns all the dollar words in the string. Provide unit test(s) for the method. (Hint problem 3 may be useful).