FAQ: Conditional Operators - Review

This community-built FAQ covers the “Review” exercise from the lesson “Conditional Operators”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Java

FAQs on the exercise Review

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in #get-help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to #get-help and #community:tips-and-resources. If you are wanting feedback or inspiration for a project, check out #project.

Looking for motivation to keep learning? Join our wider discussions in #community

Learn more about how to use this guide.

Found a bug? Report it online, or post in #community:Codecademy-Bug-Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

As the code is written now, if you would enter a count number of <1 || >8 for a reservation in the main method, the outcome would be (if restaurantCapacity >= guestCount && isRestaurantOpen is true):

Invalid Reservation
Reservation Confirmed
Please enjoy your meal!

So what could you add to the code so that if the reservation is invalid the reservation isn’t then confirmed?

Many thanks for a response:)


I changed it to:

if (count < 1 || count > 8) {
System.out.println(“Invalid reservation!”);
} else {
guestCount = count;
restaurantCapacity = capacity;
isRestaurantOpen = open;


I’m having trouble creating instances in main, here’s my code

Reservation burger = New Reservation(8, 12, true, true);


any help would be appreciated.

You don’t need to mark isConfirmed in main() as it is classified in confirmReservation(). Your reservation should only read

Reservation burger = New Reservation(8, 12, true);


Hi! :wave:

I’m adding the following sample code in main():

  public static void main(String[] args) {
    // Create instances here
    Reservation individualReservation = new Reservation(1, 4, true);
    Reservation groupReservation = new Reservation(20, 8, true);
    System.out.println("For the individual reservation, status is " + individualReservation.confirmReservation());

but I’m getting back the error:

Reservation.java:38: error: 'void' type not allowed here
    System.out.println("For the individual reservation, status is " + individualReservation.confirmReservation());
Reservation.java:39: error: 'void' type not allowed here
2 errors

I’ve checked against other sample code and can’t understand what’s wrong. Why is main() complaining about a void type not allowed when neither confirmReservartion() nor informUser() accept parameters?

Thank you! :pray:

i am completely sure, but i guess what you doing is trying to print a print statement. callling individualReservation.confirmReservation() already prints out a statement but then again you are printing the print statement. maybe thats whats causing the errors.

This question if about the Review. Can someone show me what the code would look like where you create instances in the main() that run every possible conditional branch? I clicked on view solution so I could understand this, and it didn’t change the code at all it just showed the same code as before clicking view solution. Thank you for any help.

Why does the code print “Unable to confirm reservation, please contact restaurant.”
When isConfirmed is true?
I need a answer

You need to post your code. Line 27 will always default to false unless the variable is set, or it is unreachable for some reason.

Take a look at the order in which you call your functions. As @psmilliorn mentioned, the default value for a boolean is false, meaning isConfirmed is has a value of false before it is assigned a value in confirmReservation().

Yes, isConfirmed is true, but only after it is assigned that value when confirmReservation() is called. Now take a look at where you call informUser() in relation to confirmReservation(). Why might the message printed indicate that the reservation cannot be confirmed?

confirmReservation() and informUser() must switch places.
It didn’t change the variable when informUser() was invoked?


If you walk through your code step by step, you’ll see that the value of isConfirmed was false when informUser() was called. It only becomes true when you call confirmReservation(), which happened after the call to informUser().

So, even though the final value of isConfirmed is true, its value when informUser() was called was false, meaning informUser() executed the if statement, not the else clause.

Hey Guys/Gals!

I’m brand new here to Codecademy, and I just wanted to post my snippet/screenshot of the instances I’ve created and would like some feedback on them!

So please, feel free to tell me what you think of my work, the more input, the better!! Much love and good luck out there!! :slight_smile:

Hello, I am having some troubles with this exercise. It seems that it will always print Invalid reservation, to every instances I create.

For example:

Reservation mesa2 = new Reservation (2,10,true);

It prints:

Invalid reservation!
Reservation confirmed
Please enjoy your meal!

Am I missing something? Thanks in advance for your help.

Welcome to the forums!

Can you post your full code so that we can see what’s going on? Please format it according to the guidelines in this topic.

public class Reservation {

  int guestCount;

  int restaurantCapacity;

  boolean isRestaurantOpen;

  boolean isConfirmed;


  public Reservation(int count, int capacity, boolean open) {

    if (count < 1 || count > 8) {

      System.out.println("Invalid reservation!");


    guestCount = count;

    restaurantCapacity = capacity;

    isRestaurantOpen = open;



  public void confirmReservation() {

    if (restaurantCapacity >= guestCount && isRestaurantOpen) {

      System.out.println("Reservation confirmed");

      isConfirmed = true;

    } else {

      System.out.println("Reservation denied");

      isConfirmed = false;




  public void informUser() {

    if (!isConfirmed) {

      System.out.println("Unable to confirm reservation, please contact restaurant.");

    } else {

      System.out.println("Please enjoy your meal!");




  public static void main(String[] args) {

    // Create instances here

    Reservation mesa2 = new Reservation (2,10,true);

    Reservation mesa12 = new Reservation (12,10,true);

    Reservation mesa4 = new Reservation (4,10,false);








}`Preformatted text`

Here it is. Thank you :slight_smile:

Is it because it prints for the last class (this case mesa4)?

No. If you take a look at the if statement that causes Invalid reservation! to be printed, you can see that it checks if count is either less than 1 or greater than 8.

You tried to create a reservation for 12 people on the following line.

However, this causes the if statement to evaluate to true (because 12 > 8) and therefore causes Invalid reservation! to be printed. This if statement is evaluated every time you try to create a new reservation, including the time above where you tried to make a reservation for 12 people.

I get it. But if I create all the classes I want to study and print after that, the “Invalid reservation” is the first print i get. Shouldn’t it appear only when I print for the second and third case? In my mind if I create all classes (eg: mesa2, mesa4, …) before I print the results, the message “Invalide reservation” should only appear after I get the valid results for the first class (mesa2).