• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

comparing strings

 
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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]

 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



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.
 
Christopher Laurenzano
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



It will automatically do the round for you.
 
Christopher Laurenzano
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic