Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

print invalid selction not working

 
Dustin Schreader
Ranch Hand
Posts: 102
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 308
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic