wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes default case Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "default case" Watch "default case" New topic
Author

default case

Marjorie Gyles
Ranch Hand

Joined: Nov 03, 2012
Posts: 42

My driver program asks for the letter to be entered, then asks for number of hours used. Instead of stopping when I enter a D (or other) letter, it continues until I enter the number of hours, then gives me the error message in the default. I don't get what I've done wrong.

Main



Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2853
    
  11

Your program prompts for and reads both pieces of data, a letter and a number of hours, before calling the method that has that switch statement. If you want it to validate the letter selection before you prompt for hours, then you have to put in code to do that.
Daryle Foulke
Greenhorn

Joined: Aug 27, 2009
Posts: 8

You could also uppercase you letter character and then in you case statement you only have to check for uppercase letters.



==============================
-Daryle
Marjorie Gyles
Ranch Hand

Joined: Nov 03, 2012
Posts: 42

Greg Charles wrote:Your program prompts for and reads both pieces of data, a letter and a number of hours, before calling the method that has that switch statement. If you want it to validate the letter selection before you prompt for hours, then you have to put in code to do that.


Duh, why didn't I see that? Thanks! Does this get easier with practice?
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2853
    
  11

You're welcome! Yeah, it eventually gets easier. At least you start to know where to look for problems.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: default case