aspose file tools*
The moose likes Beginning Java and the fly likes comparing strings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "comparing strings" Watch "comparing strings" New topic
Author

comparing strings

Christopher Laurenzano
Ranch Hand

Joined: Jul 25, 2009
Posts: 85
I've written a little program to compute the pay for some transcription work, but I've got a problem. The program needs to ignore where the format is "Standard" or "standard" (depending on what the user enters). I think I need to use some kind of logical OR operator, but I've used both | and || and gotten compiling errors. Here's the code. Please forgive me if it's not 'compact' enought; I'm still learning, and often added comments to clarify for myself what I'm trying to do. I haven't run it yet -- can't until it compiles correctly:



When I compile, this is the messages I get with either | or ||:

NCCTranscript.java:30: operator || cannot be applied to boolean,java.lang.String
if (transcriptFormat.equals("Standard") || ("standard")) {

Obviously I'm not using this correctly, but I can't figure out why. The program needs to ignore the case of the word, that's all.

Also: what do I need to code to get the result to only two decimal places, since it's a dollars and cents format?

I figured out the first part -- at least for now -- I just added the another .equals method to the second condition

It compiled , but didn't give the right result so I'll have to figure that out as well. Just trying to get the math right.

[Edit]Line breaks to keep within width of screen. CR[/edit]

Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183


That's where the problem is.

It would be

But the String class has helpful functions for you.

there is 'equalsIgnoreCase()' which - well - checks for equality but ignores case.

JDBCSupport - An easy to use, light-weight JDBC framework -
Christopher Laurenzano
Ranch Hand

Joined: Jul 25, 2009
Posts: 85
It worked!

Could you tell me how to shorten it to two decimal places and maybe even round the result to the nearest cent?
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183



It will automatically do the round for you.
Christopher Laurenzano
Ranch Hand

Joined: Jul 25, 2009
Posts: 85
Thanks again. May I ask if I need to change any of the code and where it should go? I got an error message when I copied it into my program. I hope I'm not asking too dumb a question. You can answer at your leisure; I'm turning in for the night (very early morning, I guess)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
An alternative way of displaying rounded numbers is to be found in this Java™ Tutorials section. Beware of long lines in code; they can be too wide for the screen.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: comparing strings