GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes Write a method that can be called, that will initialize the seating plan. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Write a method that can be called, that will initialize the seating plan." Watch "Write a method that can be called, that will initialize the seating plan." New topic
Author

Write a method that can be called, that will initialize the seating plan.

Dustin Schreader
Ranch Hand

Joined: May 25, 2009
Posts: 102
I'm having a few problems and not sure how to make it work

1. the program should not be initializing the seating plan when it is declared. I need to write a method that
I can call that will initialize the seating plan to all seats available. Then when I loop to start over,
I can just call that method to reset the seating plan.

2. Also, when the user selects E or F the program should tell them the valid rows for that ticket type to select from.
And when the user selects smoking or nonsmoking it should tell them the valid rows.

I appreciate all the help I can get thank you!

pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561

1. the program should not be initializing the seating plan when it is declared. I need to write a method that
I can call that will initialize the seating plan to all seats available. Then when I loop to start over,
I can just call that method to reset the seating plan.

2. Also, when the user selects E or F the program should tell them the valid rows for that ticket type to select from.
And when the user selects smoking or nonsmoking it should tell them the valid rows.


Let's see what you've attempted for these two problems first.
Dustin Schreader
Ranch Hand

Joined: May 25, 2009
Posts: 74
Ok well I think I've almost got the first part of it down but It is printing out 42 instead of char being *. I think I need to declare a char or something... not really sure but this is what I have so far.

Dustin Schreader
Ranch Hand

Joined: May 25, 2009
Posts: 74
Sorry I just figured it out...
Dustin Schreader
Ranch Hand

Joined: May 25, 2009
Posts: 74
I may have figured out how to print a whole bunch of * but since I put that code into my program i get a cannot find symbol. I feel like this question belongs in the beginning java area.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Dustin Schreader wrote:I may have figured out how to print a whole bunch of * but since I put that code into my program i get a cannot find symbol.

You're running into a scope issue in that your seatNumber variable has been declared within the main method and so is only visible from within this method. If you want it visible inside of other methods, either pass it as a parameter to the method or declare it in the class to give it class scope.

I feel like this question belongs in the beginning java area.

Agree.

Another thing you must do is be sure to enclose all blocks in curly braces even if it's an if block with only one line of code. Doing this will save your tail in the future, trust me. Also watch out for pesky semi-colons at the end of the boolean condition of an if block, while loop, for loop and the like as this will short-circuit the loop, i.e.,

Dustin Schreader
Ranch Hand

Joined: May 25, 2009
Posts: 74
Great thank you for the help, I did get it working now.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Dustin Schreader wrote:Great thank you for the help, I did get it working now.


Yeah! Congrats!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Dustin Schreader wrote:I feel like this question belongs in the beginning java area.

Well, since Pete agrees, how can I disagree?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39053
    
  23
You realise that chars like 'a' and 'A' are not letters, but numbers? You can do arithmetic on them. You can try printing 'a' % 0x20 - 1 as a way of converting 'a' to 0. Remember 0x20 is 32 in decimal. That might get rid of those awkward looking switch blocks. It will fall down, however, when you get to 9 seats width and you go from H to J missing out I!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Write a method that can be called, that will initialize the seating plan.