tags | languages |
---|---|
beginner, instance-variables, oop, methods |
objc |
Let's represent a sentence in code.
- First create a new class called
FISSentence
- We are going to represent our sentence as an
NSArray
ofNSString
s. So to represent the sentence "How are you?" we would have an array like this@[@"How", @"are", @"you?"]
. To do this we will need to hold state in our object. This means an instance variable! Create aNSMutableArray
instance variable to hold your words. - Write a method called
stringFormat
that returns anNSString
that is the full sentence. - Write a method called
numOfWords
that returns the number of words in the sentence. - Write a method called
containsWord:
that takes anNSString
to search for, and returns aYES
orNO
if that word is in the sentence. - Write an accessor method called
words
that returns the instance variable containing all the words.
- Write a method called
isProperSentence
that ensures that the first word is capitalized and the last word as a punctuation mark. - Write a method called
isEqualToSentence
that takes in anotherFISSentence
object and returns a YES or NO if the sentences are the same. Be a bit loose with that definition. If the capitalization or punctuation is a bit different that is fine.