• 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

Starting JOptionpane over (with String) and capital/lowercase

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

I'm doing a problem where I make a two dimensional array for at least four classes where the program should output the day and time of class. I've
done that but am confused how to have it go back to the question (rather than exit the program) if the user inputs an incorrect name. I've done
it with integers before but not a String. Also, I don't know how to have it so it will give the day/time regardless of case. If you input
the class with all caps it works but won't with any lowercase. I know there are to lowercase methods and what not but don't know how to
do both at the same time.

Thanks for any suggestions.

 
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ryan Bishop wrote:Hi,

I'm doing a problem where I make a two dimensional array for at least four classes where the program should output the day and time of class. I've
done that but am confused how to have it go back to the question (rather than exit the program) if the user inputs an incorrect name. I've done
it with integers before but not a String. Also, I don't know how to have it so it will give the day/time regardless of case. If you input
the class with all caps it works but won't with any lowercase. I know there are to lowercase methods and what not but don't know how to
do both at the same time.

Thanks for any suggestions



To make it go back to the question (rather than exit the program) if the user inputs an incorrect name you will have to make use of a looping construct such as a while, do-while and set the condition to true.

Next step within the while loop you ask the user for input as usual then check to see if the input is valid using an if condition using the equalsIngoreCase() method instead of the equals() method. If the condition evaluates to be true you supply the feedback message and break out of the loop else you just continue with the loop.
 
Ryan Bishop
Ranch Hand
Posts: 143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rico Felix wrote:You can use the equalsIgnoreCase() method instead of the equals() method.



Ugh...I'm so dumb. Thank you!
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ryan Bishop wrote:Ugh...I'm so dumb. Thank you!



You aren't dumb, you just probably didn't have that information or just wasn't thinking straight at the moment...

No problem...
reply
    Bookmark Topic Watch Topic
  • New Topic