I'm am trying to invoke boolean method isFirstClassFull and the method needs to detect if first class seats are all filled up checking each component of the array to make sure there is still an * left (* means that particular seat is empty). When firstclass is filled up (X means the seat is taken therefore firstClass array rows 1 and 2 should be full of X's) the boolean method should return printing and then send the user back to choose whether they would like E - Economy or F - First Class. Any Ideas on how to make this program run properly will be helpful and please let me know if anything I wrote is unclear thank you.
Anyway, if i got that right, if * means that the seat is empty, then isFirstClassFull should return false not true.
Well i would write your method in the following way: (There's a ; you have to delete at line 284 of your code)
Sorry I noticed that a little bit after I tried compiling the code but if I switch the false and true around it just starts off at the begining giving me the S.O.P("sorry full"); am I invoking the boolean method the wrong way?
When we read "isFirstClassFull", we logically expect true to be returned when the seats are full. isFirstClassFull ? Yes, they are. No, they aren't. The way you are using it makes it very difficult to understand. You should use Nicola's version and call :
I found the problem, it does work but only if the entire array is full of X's, the problem is first class spands from rows one and two, if rows 1 and two are full the message wont print out because rows 1 through 13 need to be full of X's in order for the message to print out. I need to have the message print out if only first class is full (rows 1 & 2). Any ideas?
As Christophe said, you could define a constant representing the rows dedicated to first class seats, let's say FIRST_CLASS_ROWS (in your case FIRST_CLASS_ROWS=2 ) , and use it in your external loop's end condition.
lol sure since I'm going to make a method for each I might as well specify which rows lol thank you. I think its time to go out for a coffee run I can't believe i didn't think of that!
Oh did you just edit that last message and simplify another statement?
Actually I might have messed of some of my code accidently but I think I got it back but now after the results I get and your last comment I'm feeling confused again. Here is what I have and it prints out sorry full right away.
Awesome it works! Yes I believe that i wanted rows 0 and 1 but now i'll need to make one of these for rows 2 through 6 and 7 through 14 (I think those would be the correct row numbers) will it still work the same for the other methods that I want to create for the smoking and non smoking rows if I just copy and paste the isFirstClassFull method and change the names of a few things or will have have to specify that i need rows 2-6 since these are not the first rows that pop up in the array, does that make sense?
Never mind I'll just change
for (row = 2; row < FIRST_CLASS_ROWS; row++) //<=======this to two istead of starting out at 0
for (col = 0; col < seatNumber[row].length; col++)
if (seatNumber[row][col] == '*')
Thank you Actually thats the second time I heard about using the curly braces, I will try to start using them more naturally but for now I'll finish up the program first and then add them in. According to the specifications of the assignment I need seperate methods to assign firstClass, smoking, and non-smoking. So I decided to split everything up and I'm not sure what I have to return.
Oh Sure I see what you mean its rows 7 up to 12 since it starts counting with 0, 1, 2, 3, 4.... So I need to change the value from 6 to 12 thank you, but what about the other methods that I just created, was I going about creating them the right way? I'm getting an error at End of assignFirstClass Method its saying that I need to return some sort of value, did I create these extra methods wrong?
I just wasn't sure if that method is supposed to be a public static void or a public static (something), I figured since those methods are supposed to output a message letting the user know there are no more spots left, its a String because it will return "Sorry this class is full" message. Is that proper thinking or should I make it void?