|
Assignment #2
Due Date October 30
CIT 2266 Object Oriented Programming
Objective:
To develop skills manipulating strings and becoming familiar with the String class
Converting primitive type to Objects
Converting Object to primitive types
Converting one data type to others
Directions:
Design a class named MyString that implements the following methods
1. Write a static method isSubString in the class MyString that searches for a specific
string (could be a character or a word) within another string; the method must return
true if the former exists in the latter string otherwise the method must return false.
For example the following calls will return true
MyString.isSubString(“cat”,”the cat in the hat.”)
MyString.isSubString(“he cat”,”the cat in the hat.”)
MyString.isSubString(“at.”,”the cat in the hat.”)
while the following will return false:
MyString.isSubString(“bat”,”the cat in the hat.”)
MyString.isSubString(“mouse”,”the cat in the hat.”)
MyString.isSubString(“at!”,”the cat in the hat.”)
2. Write a non-static method isSubString in the class MyString that searches for a
specific string (could be a character or a word) within the object’s data; the method
must return true if the argument is in the object’s data otherwise the method must return
false.
For example the following calls will return true
MyString sentence = new MyString(“the cat in the hat.”);
sentence.isSubString(”cat”);
sentence.isSubString(“he cat”) ;
bool found = new MyString(“the cat in the hat.”).isSubString(“at.”);
while the following will return false:
sentence.isSubString(“bat”)
sentence.isSubString(“mouse”)
sentence.isSubString(“at!”)
|