Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

print invalid selction not working

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
He was expelled for perverse baking experiments. This tiny ad is a model student:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic