954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

"String class"

write and test a class that can be used to create and object whose instance string variable can be initialised to a string constant such as:
"I fined that the harder I work the more luck I seem to have"

the class need to provide the following methods

A method to diplay an object's string.
A method that given a character, it returns the number of times that characte occurs in the string within the object.
eg: the character 'e' occurs 7 times within the sample string.


Please help me with this

Hjays
Newbie Poster
2 posts since Jul 2004
Reputation Points: 10
Solved Threads: 0
 

Ok , you want something like this:

Class StringProg has the 2 methods you require:
---------------------------------------------------------------

public class StringProg
{

String s;
int count = 0;

//constructor
public StringProg(String sIn)
{
s = sIn;
}

//method to diplay string
public void displayString()
{
System.out.println ("\nYour String: " + s);
}

//method to find character
public void findChar(char letter)
{

for (int i = 0; i

rickste_r
Newbie Poster
16 posts since Jul 2004
Reputation Points: 10
Solved Threads: 0
 

Hello rickste_r

Thankyou very much for the help. It was very kind of you.

yours,
Hjays

Hjays
Newbie Poster
2 posts since Jul 2004
Reputation Points: 10
Solved Threads: 0
 

rickste_r,
Don't give out homework for free! They're never going to learn anything if you do it for them. There is nothing wrong with helping them, but DON'T do it for them!
And also, use the [*code] and [/code] tags around your code please (be sure to take off the *).

Thank you.

Iron_Cross
Junior Poster
117 posts since Jul 2003
Reputation Points: 46
Solved Threads: 2
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You