• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to call constructor in a method from same class  RSS feed

 
Abad Ashraf
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The String constructor takes the sentence and converts it to lowercase with non-alphabetic characters removed. And for uniqueTerms I need to put commas between each word, so how do I go about calling the constructor to the method uniqueTerms? I know I need this(), but how do I apply it?





 
Carey Brown
Saloon Keeper
Posts: 3315
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you learned about collections yet? To track unique (actually you mean "distinct") words and their frequency, a Map is the best choice.
Where String is your word and Integer is the count of occurrences. Maps guarantee that the "word" only appears once.

You shouldn't need a setUniqueTerms() method. The Document constructor should handle this.

And this doesn't do what you think it does
You probably want
 
Abad Ashraf
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately I cannot use hashmaps or lowercase(), only regex methods like split, replaceAll and matches.
 
Carey Brown
Saloon Keeper
Posts: 3315
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't use regex, split, or replaceAll to convert a String to lower case.
 
Abad Ashraf
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So then it would be possible to convert it to lowercase without regex methods?
 
Carey Brown
Saloon Keeper
Posts: 3315
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abad Ashraf wrote:Unfortunately I cannot use hashmaps or lowercase(), only regex methods like split, replaceAll and matches.
Not being able to use HashMaps I understand. Not being able to use toLowerCase() seems ridiculous. It also makes it very difficult for anyone to help you without knowing the complete list of what you can't use.

Is this some sort of puzzle or perhaps one of those challenge problems where you have to go through head banging to figure out how to do something using only a subset of Java's capabilities when Java has a way to perform the task very simply.

Where is this assignment coming from?

[edit] Going back to some of your other topics I see the same pattern of severe problem constraints.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!