wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes print invalid selction not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "print invalid selction not working " Watch "print invalid selction not working " New topic
Author

print invalid selction not working

Dustin Schreader
Ranch Hand

Joined: May 25, 2009
Posts: 102
When I run the program its saying it can't find the row symbol and it's probably because I didn't declare it yet, but the row input is set in another method, I want assignFirstClass to check whether the user enters 1 for row one or 2 for row two and if the user inputs anything else such as a letter or any numbers that are not 1 or 2 they will recieve a message saying Invalid row, you may only choose row 1 or 2! Would assignFirstClass call the method chooseSeat somehow?
Nicola Garofalo
Ranch Hand

Joined: Apr 10, 2010
Posts: 308
Hallo Dustin,
nice to see your airplane reservation program again

Well row variable is not defined in your method, why do you think you could use something you don't even declare?


Bye,
Nicola
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

A few comments about assignFirstClass:
1. Do you need to declare rowStart and rowEnd ? Maybe rowStart, if the first class seats are not the first seats in the place. But rowEnd ? You already have FIRST_CLASS_ROWS.
2. You call isFirstClassFull and print a message, but you don't return.
3. It seems logical to make chooseSeat return the chosen seat

[My Blog]
All roads lead to JavaRanch
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Moreover, I think you should declare where each section starts from and ends to, in some variables. Smoking seats are from 8 to 13 rows, Non smoking seats are from 3 to 7... Get all these hard coded numbers out of the methods. By doing so, you'll be able to get rid of FIRST_CLASS_ROWS.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

A few comments:

File headers: We don't need to see those; you're already asking us to look at almost 500 lines of code--make it as easy as possible.

Needless repetitive redundancy: What's the purpose of this?Why do you initialize the value twice?Use your constants. You defined constants for the values you're initializing to (delta an index tweak). Why bother, if you're not going to use them everywhere? Sure source of error at some point.

Maximize vertical locality. Declare your variables near their first use; doing so clearly separates functional "chunks" and reduces cognitive overhead. It also makes spotting refactorings easier.

Use math when you can. The following is math, not conditional (delta a range check):Looks like colNo = col - 'A', no? A range check before the math ensures validity. The same holds true for the (col != 'A' && col != 'B' && etc...)--there's no need to spell out each entry by hand, and it's brittle and error-prone.

"End of fooBar method" comments: Ditch them; useless noise. If your indentation is correct it's obvious where they end, and there's already a big Javadoc chunk before the next method.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: print invalid selction not working
 
Similar Threads
do {} while statement illegal start of type
Write a method that can be called, that will initialize the seating plan.
Illegal start of type
Logic problem or invoke method problem