> I have seen that the toLowerCase exists, but I need
> to make a method for this Word class in order to use
> it. I tried putting the characters of the string
> portion in a character array, but I kept getting a
> dereferencing error.
I don't understand what you did other than somewhere I guess you tried to call toLowerCase or some other method on a char probably.
Post your code.
So your problem isn't really "Is there a way to convert the case of a string?", but rather, you have a bug in your code.
You'll get better responses if you're more forthcoming with the real issues.
That includes posting the actual error message you're getting, and the actual code that's causing it.
> I have seen that the toLowerCase exists, but I need to make a
> method for this Word class in order to use it. I tried putting the
> characters of the string portion in a character array, but I kept getting a dereferencing error.
Then you question isn't about converting the case of a String, Its about how to write code!
If you need further help then you need to create a "Short, Self Contained, Compilable and Executable, Example Program (SSCCE)",
see http://homepage1.nifty.com/algafield/sscce.html,
that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
Don't forget to use the "Code Formatting Tags",
see http://forum.java.sun.com/help.jspa?sec=formatting,
so the posted code retains its original formatting.
Gee, I'm slow at the reply...
Message was edited by:
camickr
Also in cases like this, when you have to do things because an assignment requires you to, but these things would normally be considered awkward or extraneous (e.g., duplicating existing APIs) you should probably just announce it as such, and even quote the homework assignment in the question.
Otherwise, as you've seen, people will do the reasonable thing and point you to the API, which normally is the correct thing to do but in this scenario just wastes their time and yours.
Here is the code for the Word class I created:
public class Word
{
private String Phrase;
private int counter;
//Empty Constructor
public Word()
{
Phrase = null;
counter = 0;
}
//constructor with 2 arguments
public Word(String phr, int cnt)
{
Phrase = phr;
counter = cnt;
}
//Constructor with one argument
public Word(String phr)
{
Phrase = phr;
counter = 0;
}
//equals() method
public boolean equals(Word looking)
{
boolean status;
if(Phrase.equals(looking.Phrase)&& (counter != looking.counter))
status = true;
else
status = false;
return status;
}
//toLowerCase
public String toLowerCase(String shifter)
{
char ch;
int lng;
lng = shifter.length();
for(int i = 0; i < lng; i++)
{
ch = shifter.charAt(i);
ch = shifter.toLowerCase(ch);
}
}
//compareTo method
//toString method
public String toString()
{
String describer = Phrase + ", " + counter;
return describer;
}
//setPhrase
public void setPhrase(String p)
{
Phrase = p;
}
//setCount
public void setCount(int c)
{
counter = c;
}
//getword
public String getWord()
{
return Phrase;
}
//getcount
public int getCount()
{
return counter;
}
}
The error I get is:
Word.java:50: cannot find symbol
symbol : method toLowerCase(char)
location: class java.lang.String
ch = shifter.toLowerCase(ch);
You're calling String.toLowerCase(charVariable)
if you look at String, you'll see that it doesn't have a call of this method that takes a character argument and returns a char.
Have a look at Character:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Character.html#toLowerCase(char)