0% found this document useful (0 votes)
17 views

Csc110 Program 3 - Mystring: Due: Dec 4 Points: 100

The document describes a program assignment to create a MyString class that performs similar string operations to the Java String class but without using any Java string methods except in the constructor. The MyString class should have private character array and size data members and public methods like toString(), charAt(), contains(), equals(), compareTo(), indexOf(), length(), and replace() to manipulate and work with string data. Students are tasked with writing the MyString class and a test driver class to thoroughly test each method.

Uploaded by

Ted Willis
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Csc110 Program 3 - Mystring: Due: Dec 4 Points: 100

The document describes a program assignment to create a MyString class that performs similar string operations to the Java String class but without using any Java string methods except in the constructor. The MyString class should have private character array and size data members and public methods like toString(), charAt(), contains(), equals(), compareTo(), indexOf(), length(), and replace() to manipulate and work with string data. Students are tasked with writing the MyString class and a test driver class to thoroughly test each method.

Uploaded by

Ted Willis
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

CSC110 Program 3 - MyString

Due: Dec 4 Points: 100 Write a class that performs similar operations as the Java String class. Use only private data members and public methods. Do NOT use any existing String methods from the Java String class in yString implementations. The only exception is the constructor!String newString" and toString( ) as described belo#. Do NOT use ArrayLists. . Data members$ array of %& characters si'e ( current number of characters in the array ethods$

MyString( ) Creates an array of 25 characters and sets size to 0. MyString( String newString ) Creates an array of 25 characters. Copies each character from newString into the array and sets the value of size. A ma imum of 25 characters can !e stored. "se only String methods length( ) and charAt( ) to write this method. MyString( #yString oldString ) Creates an array of 25 characters. Copies each character from newString into the array and sets the value of size. "se only String methods length( ) and charAt( ) to write this method.
String toString()

$eturns the #yString array of characters as a String.


char charAt(int index) $eturns the char value

at the specified inde . %f the inde if invalid& return the character at

inde zero.
boolean contains(char ch)

$eturns true if and only if this #yString contains the char value. 'therwise false is returned. (his method is not case sensitive.
boolean equals(MyString anotherMyString)

$eturns true if this #yString contains the same characters as the #yString parameter o!)ect.
int compareTo(MyString anotherString)

Compares two #yString o!)ects. return *+ if this o!)ect is less than the parameter o!)ect. return 0 if the two #yStrings match return ,+ if this o!)ect is greater than the parameter o!)ect
int indexOf(char ch)

$eturns the inde within #yString of the first occurrence of the specified character. %f the character does not e ist& return *+.
int length()

$eturns the num!er of characters store in the array. void replace(char oldChar, char newChar) $eplaces all occurrences of oldChar with newChar. (his method is case sensitive.

Write a test Driver that thoroughly tests each method. User input is not necessary) Strings can be hard coded into the test Driver. Output from the test Driver should be descriptive !#hat is expected and actual results". Submit yString.*ava) TestDriver.*ava and a U + class diagram.

You might also like