chapter 10 Flashcards
how do you combine conditions with an extra set of conditions?
adding conditional operators to the condition can add an extra set of conditions.
what are some examples of conditional operators and what do they do?
logical operators such as && (and) ||(or) !(not)
what does an exclamation point mean in a java program?
it is a negative which means no or not
when using an or operator in a condition, how does the condition equal true?
that which is on the left and the right of the or operator must be true in order for that codition to be true.
how would you write something like 3 to 10 guests in a java program and how is the wrong way to write it that most people make the common mistake when trying to write this?
the correct way to write this is 3 <= guests && guests <= 10 and the common mistake peope make when combining comparisons is that they would write it this way:
3 <= people <= 10 you need the and operator to let the computer know what you mean
how do you form the opposite of an existing condition?
change >= to it’s opposite without the equal sign < and change < to >= and change && to ||
if you are using a lot if statements in your code, what way is the best way to write your code so it is easier to read?
the use of booleans in your code means you won’t need to use < signs or double equal signs in the if statements if you have many if statements. you will just write these signs once when assigning the boolean values.
what must you add when you have more than one group of comparisons within an if statement?
make sure that you add parentheses to enclose each group of comparisons as well as adding && or an || operator to seperate each group of comparisons.
what can you do if you do not want to use so many if statements in your code?
you can use nested if statements
in what circumstance is using nested if statements necessary to make code more manageable, easier to read and less writing?
Using nested if statements can be convenient when you want to check for conditions that are interdependent and hierarchical, where each level of the nested conditions provides additional filtering or specificity
when using nested if statements, what should you avoid so that there isn’t much clutter and it’s easier to read?
make sure you only use no more than 2 to 3 interdependent nested if or nested else statements at a time or it can be confusing to look at.
what is an enum type of variable?
it’s like a boolean giving you more than 1 option to choose from but an enum holds 3 or more options and is not limited to just a truth or false answer but more than 3 words such as days of the week which are the constants in an enum type.
what is constant in a enum type?
it is the options to choose from that are contained within the enum type.
what is the enum type name?
it is the name you assign to the enum type which contains the constants for example if it were days of the week you would write
enum day {MONDAY, TUESDAY, WEDNESDAY, etc.}
what is something you must remember when writing the constants of an enum type? and why?
make sure to capitalize the constants to distinguish that they are fixed values