• Post Reply Bookmark Topic Watch Topic
  • New Topic

Starting JOptionpane over (with String) and capital/lowercase  RSS feed

 
Ryan Bishop
Ranch Hand
Posts: 143
5
  • Mark post as helpful
  • send pies
  • 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.

 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!