Deck 5: Making Decisions

Full screen (f)
exit full mode
Question
An alternative to using a Boolean expression, such as someVariable == 10, is to store the Boolean expression's value in a Boolean variable.
Use Space or
up arrow
down arrow
to flip the card.
Question
Although it is possible to block statements that depend on an if, you cannot likewise block statements that depend on an else.
Question
Computers contain switches that are set to on or off.
Question
When you place a block within an if statement, it is crucial to place the ____ correctly.

A) periods
B) angle brackets
C) commas
D) curly braces
Question
A ____ consists of written steps in diagram form, as a series of shapes connected by arrows.

A) pseudocode chart
B) flowchart
C) sequence structure
D) decision structure
Question
A(n) ____ statement is the decision structure you use when you need to take one or the other of two possible courses of action.

A) Boolean
B) dual-alternative if
C) single-alternative if
D) if…else
Question
When writing a statement with the two-line format, you must be sure to type a semicolon at the end of the first line in order to ensure accurate results.
Question
The simplest statement you can use to make a decision is the ____ statement.

A) this
B) Boolean
C) true false
D) if
Question
A logical structure called a(n) ____ structure is when one step follows another unconditionally.

A) straight
B) decision
C) sequence
D) unconditional
Question
Statements in which an if structure is contained inside another if structure are commonly called ____ if statements.

A) nested
B) logical
C) blocked
D) inside
Question
When you block statements, you must remember that any ____ you declare within a block is local to that block.

A) method
B) expression
C) variable
D) decision
Question
Although not required, it is common procedure to align the keyword if with the keyword else.
Question
When you execute an if…else statement, only one of the resulting actions takes place depending on the evaluation of the ____ following the if.

A) Boolean expression
B) keyword
C) else statement
D) independent statement
Question
Just as you can block statements that depend on an if, you can also block statements that depend on a(n) ____.

A) Boolean expression
B) else
C) constant
D) operator
Question
In the switch structure, break is followed by one of the possible values for the test expression and a colon.
Question
You write pseudocode in everyday language, not the syntax used in a programming language.
Question
When you use nested if statements, you must pay careful attention to placement of any else clauses.
Question
When you create a block, you must place multiple statements within it.
Question
When an expression containing a ____ is part of an if statement, the assignment is illegal.

A) single equal sign
B) greater than sign
C) double equal sign
D) Boolean value
Question
Range checking and the switch statement are tools programmers can use for effective decision making.
Question
____________________ is a tool that helps programmers plan a program's logic by writing plain English statements.
Question
A(n) ____________________ structure is one that involves choosing between alternative courses of action based on some value within a program.
Question
You are never required to use a switch structure; you can always achieve the same results with nested ____________________ statements.
Question
When working with logical operators, you can always use ____ to change precedence.

A) conditional operators
B) break statements
C) parentheses
D) semicolons
Question
When using equals and not equals for comparisons with objects, you compare the objects' ____ instead of actual values.

A) reference fields
B) primitive data types
C) Boolean values
D) memory addresses
Question
if (quotaAmt > 100 || sales > 100 && productCode == "C") bonusAmt = 50;
When the above code is executed, which operator is evaluated first?

A) &&
B) ==
C) ||
D) =
Question
You can leave out the ____ statements in a switch structure.

A) break
B) switch
C) if
D) case
Question
The AND operator is written as two ____.

A) plus signs
B) equal signs
C) ampersands
D) asterisks
Question
Failing to include a complete ____ on each side of an && operator in an if statement is a common error in Java programming.

A) mathematical expression
B) Boolean expression
C) variable
D) operator
Question
The ____ operator is written as the exclamation point ( ! ).

A) equality
B) AND
C) assignment
D) NOT
Question
You can use the ____, which is written as ||, if you want some action to occur when at least one of two conditions is true.

A) conditional OR operator
B) logical AND operator
C) range check
D) switch statement
Question
Match each term with the correct statement below.
a.relational operator
f.pipes
b.conditional operator
g.dual-alternative
c.Boolean values
h.!
d.equality
i.AND operator
e.switch statement
true and false
Question
____________________ statements are particularly useful when two conditions must be met before some action is taken.
Question
Both & and | are valid Java operators, but they operate on ____________________ rather than making comparisons in logical conditions as && and || do.
Question
A(n) ____ is a series of if statements that determine whether a value falls within a specified range.

A) scope check
B) if check
C) range test
D) range check
Question
A ____ checks a value, and based on the result performs one of two actions.

A) short-circuit structure
B) sequence structure
C) decision structure
D) block structure
Question
The ____ requires three expressions separated with a question mark and a colon.

A) flowchart
B) conditional operator
C) sequence structure
D) conditional statement
Question
The compiler does not take indentation into account when compiling code, but consistent indentation can help readers understand a program's ____.

A) machine language
B) class
C) decision
D) logic
Question
The ____ statement is useful when you need to test a single variable against a series of exact integer, character, or string values.

A) switch
B) if
C) else
D) break
Question
The ____ operator is always evaluated before the OR operator.

A) Assignment
B) AND
C) Conditional
D) Logical
Question
Describe how a sequence structure works.
Question
Why would a programmer execute more than one statement that depends on the evaluation of a Boolean expression, and how could he or she do it in Java?
Question
Match each term with the correct statement below.
a.relational operator
f.pipes
b.conditional operator
g.dual-alternative
c.Boolean values
h.!
d.equality
i.AND operator
e.switch statement
Two ampersands
Question
Within an if or an else statement, how can you code as many dependent if statements as you need?
Question
Why would a programmer use an AND operator when using nested if statements?
Question
Explain the difference between a single-alternative if structure and a dual-alternative if structure. When would it be necessary to use a dual-alternative if structure?
Question
Match each term with the correct statement below.
a.relational operator
f.pipes
b.conditional operator
g.dual-alternative
c.Boolean values
h.!
d.equality
i.AND operator
e.switch statement
Used in the OR operator
Question
List and explain the keywords used with the switch statement.
Question
Match each term with the correct statement below.
a.relational operator
f.pipes
b.conditional operator
g.dual-alternative
c.Boolean values
h.!
d.equality
i.AND operator
e.switch statement
A double equal sign
Question
What is wrong with the following statement? How could you correct it?
if(payRate < 5.85 && payRate > 60)
System.out.println("Error in pay rate");
Question
Explain the use of the NOT operator.
Question
Match each term with the correct statement below.
a.relational operator
f.pipes
b.conditional operator
g.dual-alternative
c.Boolean values
h.!
d.equality
i.AND operator
e.switch statement
An alternative to using a series of nested if statements
Question
In Boolean expressions, when you want to execute more than one statement based on the results of the expression, you place statements within a block. What is a block and why is it important in decision statements? Why are curly braces crucial when blocking an if statement?
Question
An alternative to using a Boolean expression, such as quizScore == 10, is to store the Boolean expression's value in a Boolean variable. How could you express this in Java?
Question
Why would a programmer need to use a range check? Give an example.
Question
Why do programmers use pseudocode?
Question
Match each term with the correct statement below.
a.relational operator
f.pipes
b.conditional operator
g.dual-alternative
c.Boolean values
h.!
d.equality
i.AND operator
e.switch statement
Two possible courses of action
Question
Match each term with the correct statement below.
a.relational operator
f.pipes
b.conditional operator
g.dual-alternative
c.Boolean values
h.!
d.equality
i.AND operator
e.switch statement
> or <
Question
Match each term with the correct statement below.
a.relational operator
f.pipes
b.conditional operator
g.dual-alternative
c.Boolean values
h.!
d.equality
i.AND operator
e.switch statement
The logical NOT operator
Question
Match each term with the correct statement below.
a.relational operator
f.pipes
b.conditional operator
g.dual-alternative
c.Boolean values
h.!
d.equality
i.AND operator
e.switch statement
Separated with a question mark and a colon
Question
Write a nested if statement that will check if the variable qtySold is greater than the QTY_QUOTA constant. If true, evaluate a second expression that will check if the variable totalSales is greater than the constant SALES_QUOTA. If the second expression is also true, create an assignment statement that will assign the constant BONUSAMT to the variable bonus. After BONUSAMT is assigned, the if structure ends.
Question
Create an if…else statement that will check if the maxValue variable is equal to 100. If true, create a println statement that will output "Max reached". If false, create a println statement to output "Keep trying".
Question
Write a single-alternative if statement that will check if a variable named maxValue is equal to 100. If true, use a println statement to output "You have reached the limit".
Question
if(qtySold > QUOTA)
bonusPay = 50;
totalPay = regPay + bonusPay;
System.out.println("Your totalPay amount is " + totalPay);
Why is the above code incorrect? What would be required to make the code execute correctly?
Question
Create an if statement that will check if the variable salesAmt is greater than the constant SALES_QUOTA. If true, create a block statement that will calculate salesAmt * BONUS_PERCENT and store the result in a variable named bonusPay. The block statement will then compute totalPay by adding salesAmt to bonusPay. Outside of the if structure, add a println statement that will output the totalPay value.
Question
if (maxValue = 100)
System.out.println ("Your limit has been reached");
Why is the above if statement illegal? How would you fix it?
Question
Create a switch statement that will test the value of a variable named score. If score has a value of 5, create a println statement that will output "Excellent". If score has a value of 4, create a println statement that will output "Great". If score has a value of 3, create a println statement that will output "Good". If score has a value of 2, create a println statement that will output "Fair". If score has a value of 1, create a println statement that will output "Needs improvement". If score does not contain a matching value for any of the case statements, create a println statement that will output "Retake test".
Question
public class Student
{
private int studentNum;
private int studentScore;
public int MAX_NUM = 500;
public int MAX_SCORE = 100;
Student(int num, int score)
{
}
Decision making can be used to control the allowed values in an object's fields. In the above code, the Student class contains two fields that hold a student number and a score. A constructor accepts values for these fields as parameters. Write the code between the curly brackets that will determine whether the value of num is less than the MAX_NUM constant. If true, assign the value of num to studentNum. Otherwise, assign the value of MAX_NUM to the studentNum. Then check if the value of score is less than or equal to MAX_SCORE. If true, assign the value of score to studentScore. Otherwise, assign 0 to studentScore.
Question
Create an if statement that checks if the variable salesAmt is greater than or equal to the QUOTA_AMT constant. Use the logical OR operator to also check if salesAmt is greater than or equal to the HIGH_SALES constant. If either expression is true, assign the value of the LARGE_QUOTA constant to the variable bonusAmt.
Question
if(firstValue == secondValue)
{
int total = firstValue + secondVaue;
System.out.println("The values are equal");
}
System.out.println("The total is " + total);
Why will the above println() statement cause an error?
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/70
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 5: Making Decisions
1
An alternative to using a Boolean expression, such as someVariable == 10, is to store the Boolean expression's value in a Boolean variable.
True
2
Although it is possible to block statements that depend on an if, you cannot likewise block statements that depend on an else.
False
3
Computers contain switches that are set to on or off.
True
4
When you place a block within an if statement, it is crucial to place the ____ correctly.

A) periods
B) angle brackets
C) commas
D) curly braces
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
5
A ____ consists of written steps in diagram form, as a series of shapes connected by arrows.

A) pseudocode chart
B) flowchart
C) sequence structure
D) decision structure
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
6
A(n) ____ statement is the decision structure you use when you need to take one or the other of two possible courses of action.

A) Boolean
B) dual-alternative if
C) single-alternative if
D) if…else
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
7
When writing a statement with the two-line format, you must be sure to type a semicolon at the end of the first line in order to ensure accurate results.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
8
The simplest statement you can use to make a decision is the ____ statement.

A) this
B) Boolean
C) true false
D) if
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
9
A logical structure called a(n) ____ structure is when one step follows another unconditionally.

A) straight
B) decision
C) sequence
D) unconditional
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
10
Statements in which an if structure is contained inside another if structure are commonly called ____ if statements.

A) nested
B) logical
C) blocked
D) inside
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
11
When you block statements, you must remember that any ____ you declare within a block is local to that block.

A) method
B) expression
C) variable
D) decision
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
12
Although not required, it is common procedure to align the keyword if with the keyword else.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
13
When you execute an if…else statement, only one of the resulting actions takes place depending on the evaluation of the ____ following the if.

A) Boolean expression
B) keyword
C) else statement
D) independent statement
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
14
Just as you can block statements that depend on an if, you can also block statements that depend on a(n) ____.

A) Boolean expression
B) else
C) constant
D) operator
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
15
In the switch structure, break is followed by one of the possible values for the test expression and a colon.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
16
You write pseudocode in everyday language, not the syntax used in a programming language.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
17
When you use nested if statements, you must pay careful attention to placement of any else clauses.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
18
When you create a block, you must place multiple statements within it.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
19
When an expression containing a ____ is part of an if statement, the assignment is illegal.

A) single equal sign
B) greater than sign
C) double equal sign
D) Boolean value
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
20
Range checking and the switch statement are tools programmers can use for effective decision making.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
21
____________________ is a tool that helps programmers plan a program's logic by writing plain English statements.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
22
A(n) ____________________ structure is one that involves choosing between alternative courses of action based on some value within a program.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
23
You are never required to use a switch structure; you can always achieve the same results with nested ____________________ statements.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
24
When working with logical operators, you can always use ____ to change precedence.

A) conditional operators
B) break statements
C) parentheses
D) semicolons
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
25
When using equals and not equals for comparisons with objects, you compare the objects' ____ instead of actual values.

A) reference fields
B) primitive data types
C) Boolean values
D) memory addresses
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
26
if (quotaAmt > 100 || sales > 100 && productCode == "C") bonusAmt = 50;
When the above code is executed, which operator is evaluated first?

A) &&
B) ==
C) ||
D) =
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
27
You can leave out the ____ statements in a switch structure.

A) break
B) switch
C) if
D) case
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
28
The AND operator is written as two ____.

A) plus signs
B) equal signs
C) ampersands
D) asterisks
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
29
Failing to include a complete ____ on each side of an && operator in an if statement is a common error in Java programming.

A) mathematical expression
B) Boolean expression
C) variable
D) operator
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
30
The ____ operator is written as the exclamation point ( ! ).

A) equality
B) AND
C) assignment
D) NOT
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
31
You can use the ____, which is written as ||, if you want some action to occur when at least one of two conditions is true.

A) conditional OR operator
B) logical AND operator
C) range check
D) switch statement
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
32
Match each term with the correct statement below.
a.relational operator
f.pipes
b.conditional operator
g.dual-alternative
c.Boolean values
h.!
d.equality
i.AND operator
e.switch statement
true and false
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
33
____________________ statements are particularly useful when two conditions must be met before some action is taken.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
34
Both & and | are valid Java operators, but they operate on ____________________ rather than making comparisons in logical conditions as && and || do.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
35
A(n) ____ is a series of if statements that determine whether a value falls within a specified range.

A) scope check
B) if check
C) range test
D) range check
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
36
A ____ checks a value, and based on the result performs one of two actions.

A) short-circuit structure
B) sequence structure
C) decision structure
D) block structure
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
37
The ____ requires three expressions separated with a question mark and a colon.

A) flowchart
B) conditional operator
C) sequence structure
D) conditional statement
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
38
The compiler does not take indentation into account when compiling code, but consistent indentation can help readers understand a program's ____.

A) machine language
B) class
C) decision
D) logic
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
39
The ____ statement is useful when you need to test a single variable against a series of exact integer, character, or string values.

A) switch
B) if
C) else
D) break
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
40
The ____ operator is always evaluated before the OR operator.

A) Assignment
B) AND
C) Conditional
D) Logical
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
41
Describe how a sequence structure works.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
42
Why would a programmer execute more than one statement that depends on the evaluation of a Boolean expression, and how could he or she do it in Java?
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
43
Match each term with the correct statement below.
a.relational operator
f.pipes
b.conditional operator
g.dual-alternative
c.Boolean values
h.!
d.equality
i.AND operator
e.switch statement
Two ampersands
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
44
Within an if or an else statement, how can you code as many dependent if statements as you need?
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
45
Why would a programmer use an AND operator when using nested if statements?
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
46
Explain the difference between a single-alternative if structure and a dual-alternative if structure. When would it be necessary to use a dual-alternative if structure?
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
47
Match each term with the correct statement below.
a.relational operator
f.pipes
b.conditional operator
g.dual-alternative
c.Boolean values
h.!
d.equality
i.AND operator
e.switch statement
Used in the OR operator
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
48
List and explain the keywords used with the switch statement.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
49
Match each term with the correct statement below.
a.relational operator
f.pipes
b.conditional operator
g.dual-alternative
c.Boolean values
h.!
d.equality
i.AND operator
e.switch statement
A double equal sign
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
50
What is wrong with the following statement? How could you correct it?
if(payRate < 5.85 && payRate > 60)
System.out.println("Error in pay rate");
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
51
Explain the use of the NOT operator.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
52
Match each term with the correct statement below.
a.relational operator
f.pipes
b.conditional operator
g.dual-alternative
c.Boolean values
h.!
d.equality
i.AND operator
e.switch statement
An alternative to using a series of nested if statements
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
53
In Boolean expressions, when you want to execute more than one statement based on the results of the expression, you place statements within a block. What is a block and why is it important in decision statements? Why are curly braces crucial when blocking an if statement?
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
54
An alternative to using a Boolean expression, such as quizScore == 10, is to store the Boolean expression's value in a Boolean variable. How could you express this in Java?
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
55
Why would a programmer need to use a range check? Give an example.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
56
Why do programmers use pseudocode?
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
57
Match each term with the correct statement below.
a.relational operator
f.pipes
b.conditional operator
g.dual-alternative
c.Boolean values
h.!
d.equality
i.AND operator
e.switch statement
Two possible courses of action
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
58
Match each term with the correct statement below.
a.relational operator
f.pipes
b.conditional operator
g.dual-alternative
c.Boolean values
h.!
d.equality
i.AND operator
e.switch statement
> or <
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
59
Match each term with the correct statement below.
a.relational operator
f.pipes
b.conditional operator
g.dual-alternative
c.Boolean values
h.!
d.equality
i.AND operator
e.switch statement
The logical NOT operator
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
60
Match each term with the correct statement below.
a.relational operator
f.pipes
b.conditional operator
g.dual-alternative
c.Boolean values
h.!
d.equality
i.AND operator
e.switch statement
Separated with a question mark and a colon
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
61
Write a nested if statement that will check if the variable qtySold is greater than the QTY_QUOTA constant. If true, evaluate a second expression that will check if the variable totalSales is greater than the constant SALES_QUOTA. If the second expression is also true, create an assignment statement that will assign the constant BONUSAMT to the variable bonus. After BONUSAMT is assigned, the if structure ends.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
62
Create an if…else statement that will check if the maxValue variable is equal to 100. If true, create a println statement that will output "Max reached". If false, create a println statement to output "Keep trying".
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
63
Write a single-alternative if statement that will check if a variable named maxValue is equal to 100. If true, use a println statement to output "You have reached the limit".
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
64
if(qtySold > QUOTA)
bonusPay = 50;
totalPay = regPay + bonusPay;
System.out.println("Your totalPay amount is " + totalPay);
Why is the above code incorrect? What would be required to make the code execute correctly?
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
65
Create an if statement that will check if the variable salesAmt is greater than the constant SALES_QUOTA. If true, create a block statement that will calculate salesAmt * BONUS_PERCENT and store the result in a variable named bonusPay. The block statement will then compute totalPay by adding salesAmt to bonusPay. Outside of the if structure, add a println statement that will output the totalPay value.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
66
if (maxValue = 100)
System.out.println ("Your limit has been reached");
Why is the above if statement illegal? How would you fix it?
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
67
Create a switch statement that will test the value of a variable named score. If score has a value of 5, create a println statement that will output "Excellent". If score has a value of 4, create a println statement that will output "Great". If score has a value of 3, create a println statement that will output "Good". If score has a value of 2, create a println statement that will output "Fair". If score has a value of 1, create a println statement that will output "Needs improvement". If score does not contain a matching value for any of the case statements, create a println statement that will output "Retake test".
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
68
public class Student
{
private int studentNum;
private int studentScore;
public int MAX_NUM = 500;
public int MAX_SCORE = 100;
Student(int num, int score)
{
}
Decision making can be used to control the allowed values in an object's fields. In the above code, the Student class contains two fields that hold a student number and a score. A constructor accepts values for these fields as parameters. Write the code between the curly brackets that will determine whether the value of num is less than the MAX_NUM constant. If true, assign the value of num to studentNum. Otherwise, assign the value of MAX_NUM to the studentNum. Then check if the value of score is less than or equal to MAX_SCORE. If true, assign the value of score to studentScore. Otherwise, assign 0 to studentScore.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
69
Create an if statement that checks if the variable salesAmt is greater than or equal to the QUOTA_AMT constant. Use the logical OR operator to also check if salesAmt is greater than or equal to the HIGH_SALES constant. If either expression is true, assign the value of the LARGE_QUOTA constant to the variable bonusAmt.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
70
if(firstValue == secondValue)
{
int total = firstValue + secondVaue;
System.out.println("The values are equal");
}
System.out.println("The total is " + total);
Why will the above println() statement cause an error?
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 70 flashcards in this deck.