This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Can someone tell me whats wrong with this? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Can someone tell me whats wrong with this?" Watch "Can someone tell me whats wrong with this?" New topic
Author

Can someone tell me whats wrong with this?

John Swain
Greenhorn

Joined: Feb 12, 2005
Posts: 16
Hello, I am making a Temperature conversion program. Its pretty simple but i keep getting these errors and i cant figure out what im doing wrong. Any advice? Here is my code
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Are these the errors you keep getting (with different line numbers)?[code]TempConversion.java:31: 'class' or 'interface' expected
}
^
TempConversion.java:33: 'class' or 'interface' expected
^
2 errors[/code}If so, remove the final two }s. If you line up each pair of open and close braces, it will be easier to tell when this happens. Once you fix that, you can address the other syntax errors.

Otherwise, don't keep us in suspence! Post the errors you get so people can help you. Not everyone can and wants to take the time to copy your code and compile it themselves. Make it as easy as possible for people to help to maximize your chance of getting help.
John Swain
Greenhorn

Joined: Feb 12, 2005
Posts: 16
Sorry that code is alittle in correct. The errors im recieving are: Assignment 2/TempConversion.java [28:1] incompatible types
found : java.lang.String
required: char
cUnit = keyboard.readLine();
and
Assignment 2/TempConversion.java [29:1] char cannot be dereferenced
if (cUnit.equalsIgnoreCase("c"))

I dont understand why i get these errors. Please help. I have attatched my code the way its supposed to look.

David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
readLine() returns a String and equalsIgnoreCase() is a method of String, yet you have declared cUnit as a char. The first error means you cannot assign a String to a char. The second means that you cannot call methods on primitive types like char and int.
John Swain
Greenhorn

Joined: Feb 12, 2005
Posts: 16
thanks, I changed equalsIgnoreCase() to ((cUnit == 'f') || (cUnit == 'F')). there are no errors for that. I am getting confused on how to get keyboard input for type char.
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
You can use readLine() to get a String and pull off the first character (make sure there is one!) with charAt(int). I recommend familiarizing yourself with the JavaDocs for the String class as it will be very important in your coding.

There are ways to respond to the first key press without waiting for the user to hit enter, but only go down that road if you must for this assignment.
John Swain
Greenhorn

Joined: Feb 12, 2005
Posts: 16
Thanks for the help again. I looked it up in another book and i found: cUnit = (char) System.in.read(); this seems to work. Just one more question, after i compile and run the program i get the error stating: java.lang.NoClassDefFoundError: Assignment
Exception in thread "main"

any ideas what this means?
thanks once again.
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Yes, InputStream.read() will return the next byte, usually an ASCII character, so you should be okay with that for a simple program.

You need to run your program using the name of the class:It looks like you are not specifying a package name in the class, so that's all you should need. Make sure that directory has a TempConversion.class file.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can someone tell me whats wrong with this?
 
Similar Threads
Which is the best practice?
comparison methods
Using a loop w/a Switch (Case) Statement
equalsIgnoreCase
java temperature converter