Help please Java control flow instances that work in each conditional statement

Greeting friends

I am currently working through the Codecademy Java course and am very much enjoying it! However, I am having a bit of trouble understanding: [The exercise that I am currently having difficulty understanding( what is meant by “Instances that will run in each conditional statement”

Are we to create instance primitive data types, or constructors?

Any help and or example would be immensely appreciated!

You can achieve your goals!

Warmest regards!

Joseph Jones Aspiring:

Software Engineer|Writer|Astronaut

We have been given a class called Reservation. There are five println statements (1 in constructor, 4 in methods). Our goal is to create instances of the Reservation class such that every println statement gets printed at least once.

When creating an instance of the Reservation class, we need to provide three pieces of information to the constructor. We need to provide an integer value for count, an integer value for capacity and a boolean value for open.
Look at the condition in the constructor which causes the "Invalid reservation!" message to be printed. By picking a suitable value for count when creating an instance, you can get this message to print.
For the println statements in the methods, we need to pick suitable values for capacity and open such that we are able to reach every println statement at least once.
For Example,

Reservation goodRes = new Reservation(6, 7, true);

// Output:
// Reservation confirmed
// Please enjoy your meal!

By picking suitable initial values, you can create another instance and then invoke its methods to print the other two println statements. I think 3 instances will allow you to print all 5 statements [1 instance which results in invalid reservation (invalidRes), 1 instance which causes successful reservation (the example above with goodRes), 1 instance which causes failed reservation (badRes)].

1 Like