chapter 10 Flashcards

1
Q

how do you combine conditions with an extra set of conditions?

A

adding conditional operators to the condition can add an extra set of conditions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what are some examples of conditional operators and what do they do?

A

logical operators such as && (and) ||(or) !(not)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what does an exclamation point mean in a java program?

A

it is a negative which means no or not

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

when using an or operator in a condition, how does the condition equal true?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

how do you form the opposite of an existing condition?

A

change >= to it’s opposite without the equal sign < and change < to >= and change && to ||

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what must you add when you have more than one group of comparisons within an if statement?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what can you do if you do not want to use so many if statements in your code?

A

you can use nested if statements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

in what circumstance is using nested if statements necessary to make code more manageable, easier to read and less writing?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

when using nested if statements, what should you avoid so that there isn’t much clutter and it’s easier to read?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

what is an enum type of variable?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what is constant in a enum type?

A

it is the options to choose from that are contained within the enum type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

what is the enum type name?

A

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.}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

what is something you must remember when writing the constants of an enum type? and why?

A

make sure to capitalize the constants to distinguish that they are fixed values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

what is the variable of the enum type and how does it work? does the variable of the enum type have a name? what else is the enum type other than a variable?

A

the variable of the enum type can only hold 1 of several possible outcomes or options. you are to name the variable of the enum type and the enum type has a name you assign as well. the enum type is also the prefix for the constants within the enum type.

17
Q

why is it important to write out the prefixes when writing the constants in your program ? when is the only time not writing the prefixes for the constants ok?

A

if you do not use the prefixes the program will not work. the only time it is ok not to write the constants prefix is when assigning the enum type variable.

18
Q

when pairing up an enum type with if, else statements or switch statements which one is more convenient and easier to read?

A

when using an enum type it’s better to use a switch statement because of less writing clarity and you are issued warnings by the compiler before run time in case you missed any constants that are in the enum type. unlike using if and else statements, you won’t know you have missing constants in the if and else statements that were assigned to the enum type until you run the program. rule of thumb, choose to pair an enum type with a switch statement instead.