Chapter 10 Flashcards

1
Q

What are some elements that are needed in order to produce a backgammon game in a Java computer program

A

You need to combine conditions and use operators such as and and or in your code

Example

If die1 + die2 equals 8 and die1 equals die2, …

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

In a program like

8 < age && age < 8
What is the result of the code when it’s ran?

A

The value of the age variable is greater than 4 and is less than 8. The numbers 5, 6, 7, 8, 9 … are all greater than 4. But among these numbers, only 5, 6, and 7 are less than 8. So only the numbers 5, 6, and 7 satisfy this combined condition.

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

What are the symbols used in Java language when you want to use the words and and or

A

And uses two double and symbols
&&

And or uses two pipe symbols when the backslash is shifted you find the symbol
||

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

What does an exclamation point mean in Java language

A

An exclamation point In Java language means no not or nor

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

How would you rewrite this combined condition so that it is correct? Explain your answer.
3<=people<=10

A

In order to rewrite this combined condition correctly you have to use and operators the two && symbols because it just doesn’t work that other way in Java the code would be rewritten like this

3<=people && people <=10

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

When using if statements in your code, what can make the program more manageable?

A

Adding Boolean values to a program with if statements makes it more manageable

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

What are nested if statements? And how do you write them without confusing you or other users when reading your code? How many if statements and nested if statements can you use in your program?

A

A nested if statement is an if statement within an if statement. You want to make sure your indentation is correct as well as using braces in the right places otherwise you will confound whoever reads your code. You can use as many if statements and nested if statements within your program

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

What are cascading if statements? What is the basic format for cascading if statements? How many cascading if statements can you use in a program?
Do you need to use cascading if statements?

A

If you need more than 1 of 2 possible results in the output of your code by using if and else statements you need to use cascading if statements. Cascading if statements are written with else if in between the prior if statement and before the last else statement. You can use as many cascading if statements within your code. Cascading if statements are optional.

If (x) {
(A)
} else if (y) {
(B)
} else (z) {
(C)

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

What is an enum type and what 2 things can it be similar too but more easily used and read? What is the basic format for an enum type?

A

An enum type is similar to using cascading if statements that output 1 of 3 or more possible outcomes. It is also similar to a boolean type but on steroids. Instead of just two possible outcomes you can do 3 or more. The basic format for an enum type:

enum (x) { a, b, c }

(x) (y);

(y) = (x.a);
(y) = (x.b);
(z) = (x.c);

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

An enum type can result in 1 of 3 or more possible outcomes but is this the only ratio of possible outcomes?

A

An enum type can result 1 or more of 3 or more possible outcomes. Example the results can be 2 of 3 , 3 of 5 , 7 of 10 etc

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

What is the purpose for an enum type?

A

An enum type is similar to a Boolean value but instead of just two possible outcomes you can make more than two possible outcomes

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