• Post Reply Bookmark Topic Watch Topic
  • New Topic

Program won't accept command lines?  RSS feed

 
William Coville
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A friend and I are working on a project in which we must test "super anagrams" (anagrams in which all characters in the first string are found in the second). We have a driver and definitions class pasted below:


Definition



In the driver class, we get "cannot find symbol" errors at the period at left.toLowercase(), right.toLowercase(), left.deleteCharAt(j), and right.deleteCharAt(j).

Driver


In the driver class, we get "cannot find symbol" errors at the beginning of cleanStrings and isSuper, both inside and outside of the if statement.

If anyone is able to provide insight, it would be much appreciated!
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the String class have a deleteChar method? Since Strings are immutable I would have thought that unlikely. You can put your String into a StringBuilder and use its delete method, however.
Did you write toLowercase with a small “c”? Surely it should be toLowerCase?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you may want to check the API very carefully. There is no method called "toLowercase" defined for the String method. Nor is there a ToLowerCase, TOLOWERCASE, or tolowercase method.

 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never write == true or == false.
Not
if (b == true)...
but
if (b)...
Not
if (b == false)...
but
if (!b)...
The reason is that (apart from it being poor style) it is easy to write = by mistake and then you have two logic errors for the price of one.

Note that
if (!b)...
can be harder to read than
if (b)...
That means it is easier to read your program if you can arrange for your booleans to evaluate to true than to false. But sometimes that cannot be achieved.
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would be better design to have the clean strings method called from inside the anagram constructor. The anagram class should do its own cleaning, rather than having it done elsewhere. In which case give the clean method private access, so it can only be called inside the anagram class.
 
William Coville
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My friend and I have solved the problem, we did not complete the isSuper method. Thanks to all for your help!
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16059
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more remark:

Writing new String("") is more complicated (and more inefficient) than necessary. Just write "" instead:

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!