Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-03-2008, 05:05 AM
Member
 
Join Date: Dec 2008
Posts: 1
Rep Power: 0
safecracker is on a distinguished road
Default homework help/ String Searcher
Here is my assignment:
This program asks for a sentence and a search word. It prints the number of times the search word appears exactly in the sentence, and the number of times the search word appears as part of another word.

An example would be "Madam, I'm Adam" search word: adam.

So far I've written the program so that it asks the user for the sentence and search word, and then converts everything to lower case. I'm having trouble with the counts though. I've been looking through the Lang book and have found a letter counter and trying to see if I can manipulate it to look like my search word instead, but so far have failed.

Does anyone know how to count the number of times the word appears exactly and as part of another word? I'm hoping to get this finished for tomorrow morning.

Last edited by safecracker; 12-03-2008 at 05:14 AM.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 12-03-2008, 05:14 AM
Senior Member
 
Join Date: Sep 2008
Posts: 564
Rep Power: 2
emceenugget is on a distinguished road
Default
You can easily iterate through the sentence to check for a substring. Java provides a lot of tools in the String class that will help you out in achieving this.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-03-2008, 05:21 AM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,463
Rep Power: 8
Fubarable is on a distinguished road
Default
emceenugget is right on the money. I'll try to give you a head start by posting a link to the String API. Read through this and you'll find several methods worth trying out:
String (Java Platform SE 6)
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-04-2008, 01:35 AM
miss.meli's Avatar
Member
 
Join Date: Nov 2008
Location: Austin, TX
Posts: 17
Rep Power: 0
miss.meli is on a distinguished road
Default
I think you might also want to take a look at StringTokenizer if you haven't already.
__________________
miss.meli (-.-)zzZZ
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 12-04-2008, 05:58 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,513
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
I don't think StringTokernizer is a good choice for this. Regular expressions are the best, in near future StringTokernizers can be deprecated. Actually we discuss about this several times in our community.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 12-04-2008, 06:27 AM
miss.meli's Avatar
Member
 
Join Date: Nov 2008
Location: Austin, TX
Posts: 17
Rep Power: 0
miss.meli is on a distinguished road
Default
Originally Posted by Eranga View Post
in near future StringTokernizers can be deprecated
I'm new to java myself with only about a year and a half of experience , so I'm not to familiar with deprecated. What's that mean in programming?
__________________
miss.meli (-.-)zzZZ
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 12-04-2008, 06:32 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,513
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
In simple word, some method are not in implementation. Can cause several issues, like memory crash and so on. What Sun do is, they introduce new implements for that method and the existing one named as deprecated, means Suns' strongly to advice not to use and use the new one.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 12-04-2008, 06:38 AM
miss.meli's Avatar
Member
 
Join Date: Nov 2008
Location: Austin, TX
Posts: 17
Rep Power: 0
miss.meli is on a distinguished road
Default
Oh okay, that makes sense.
__________________
miss.meli (-.-)zzZZ
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 12-04-2008, 06:41 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,513
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
Originally Posted by miss.meli View Post
Oh okay, that makes sense.
Didn't you comes with such situations?

Try show() on JFrame for setVisible() and see. But you should work on IDE, and different IDEs give different results/comments.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java homework please Indulgence New To Java 1 11-03-2008 03:48 AM
Homework help... robrobrob New To Java 4 10-17-2008 05:24 AM
Need help with homework. JavaNewbie0000 New To Java 2 07-31-2008 04:06 PM
thread homework integralli Threads and Synchronization 6 06-21-2008 05:34 PM
Some input on a homework alcohole4life New To Java 1 05-23-2008 05:18 PM


All times are GMT +2. The time now is 07:27 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org