Java: Symbol Cannot Be Found?

Hey everyone! I’m working through the conditional operators review for Java and as a part of the review I am told to add some instances to my main. So I think I did that…but I keep getting an error message of “cannot find symbol”…I’m new to Java and so I’m on the verge of tears LOL.

I have racked my brain. Gone back to classes and instances. I can’t quite see what I’m doing wrong.

I know it is probably something silly. I’m lost. It has been a rough day LOL.

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 myDate = new Reservation (8, 12, true);
    System.out.println(myDate.Reservation());
  }
}

Hi @jcm9505

In your case, I think the “cannot find symbol” error is referring to an undeclared variable in your code.

On a related note, it’s more helpful if you post the entire error you’re getting rather than just a snippet. For example, if I run your code in a REPL I get the following error:

Main.java:40: error: cannot find symbol
    System.out.println(myDate.Reservation);
                             ^
  symbol:   variable Reservation
  location: variable myDate of type Reservation

I’m guessing that you’re not meant to be trying to print that out? (I don’t know how you’d print that, actually… I know you can print the class variables fine, but that line System.out.println(myDate.Reservation()); has rather confused me…)

2 Likes

Oh boy. LOL I have no clue what I am doing then. Let me go back and read again. THANK YOU FOR YOUR HELP!

1 Like

No problem, though I could very well be wrong.

I think what the exercise wants you to do is just create some Reservation instances which, when you call the class methods, will go through the different conditional paths like so:

  public static void main(String[] args) {
    // Create instances here
    System.out.println("Party of five, please!");
    Reservation partyOfFive = new Reservation(5,10,true);
    partyOfFive.confirmReservation();
    partyOfFive.informUser();
    
    System.out.println("Party of 10, please!!");
    Reservation partyOfTen = new Reservation(10,8,true);
    partyOfTen.confirmReservation();
    partyOfTen.informUser();
  }

Console output:

Party of five, please!
Reservation confirmed
Please enjoy your meal!
Party of 10, please!!
Invalid reservation!
Reservation denied
Unable to confirm reservation, please contact restaurant.

That’s not an exhaustive list, obviously, but I think that’s what it’s expecting you to do. There’s no “solution”, tbh, as it’s just an exercise of creating instances which take unique paths through your if statements… :slight_smile:

2 Likes

LOL. I’m embarrassed. I am so new. This makes so much more sense than whatever the heck I was doing.

I suppose I am confused about calling methods because I thought I couldn’t call a method that was void?

I definitely need to clear some vocab up for myself before continuing.

Thank you so much for all of your help. I OWE YOU ONE.

1 Like

Don’t be. Making mistakes is part of learning, as is asking for help. :slight_smile:

2 Likes

Thank you so much for this insight! I am also new to this and also had no clue what I was being asked to do!! This helped me a lot!