Level 88 Level 90
Level 89

[Quiz] Methods II


105 words 0 ignored

Ready to learn       Ready to review

Ignore words

Check the boxes below to ignore/unignore words, then click save at the bottom. Ignored words will never appear in any learning session.

All None

Ignore?
relational operators
are boolean expression.
Boolean expressions
have only two possible values : True and False. They are commonly found controlling the choice between the two parts through a conditional statement.
true or false
Values for Boolean expressions can be?
if (condition)
general form of the if-else statement (in Java where condition is a logical expression)
false
In the Reverse Polish notation, the operators are written before the operands.
true
(T/F) A programmer can define his/her own exceptions.
all of them
Which of the following are Java reserved words: boolean, true, false
boolean aVar;
how to declare boolean variables
can just use true or false
Why do we not declare boolean constants?
==
Equal to (Relational Operators)
!=
Not Equal (Relational Operators)
Boolean
Binary data type
=
Assignment -stores the right hand value in
variables of primitive numeric data types
Relational operators are applied mostly to what?
floating-point arithmetic is imprecise (rounding errors)
Why should you avoid using == and != for double or float variables and expressions?
references (addresses)
If you apply the == and != operators to objects, instead of comparing the values, you will be comparing two _______ to them; a potential source of bugs.
and and "or"
Java's two binary logical operators
not
-- Avoid using the "not =" operators, since this logic can be
and
A boolean (true/false) operator that evaluates to true only when both conditions are true.
OR
ll
!p ll !q
De Morgan's Law: ! (p && q) is the same as
!p && !q
De Morgan's Law: ! (p ll q) is the same as
higher (therefore "not" is applied first)
Unary operators have _______ precedence than binary operators.
parenthesis
You have to use _______ if you want to apply ! to the entire expression
arithmetic
Which has higher rank, arithmetic or relational operators?
short-circuit evaluation
if the value of the first (left) operand in a binary logical operation is sufficient to determine the result of the operation, the second operand is not evaluated
Reasons for separating rules of the game from the GUI part
(1) might need to change the GUI while leaving the game alone; (2) can reuse CrapsGame class in other applications; (3) may have future need for similar game with different rules; (4) division of labor
Cohesion
each class must represent a single concept, and all its constructors and public methods should be related to that concept
Coupling
degree of dependency between classes
minimized
In a good design, coupling should be _______.
easier
Low coupling makes it _______ to split the work between programmers and make changes to the code.
if-else-if
If a program has to handle just two or three possible actions, you should use __ _______ __ statements.
cases (code fragments)
When a switch statement is compiled, the compiler creates a table of these values and the associated addresses of the corresponding _______.
finds it in the table and jumps to the corresponding case
When the switch is executed, the program first evaluates (expression) to an integer, then it does what?
the program jumps to "default"
What happens if a switch value is not in the table?
the break statement at the end of a case
tells the program to jump out of the switch and continue with the first statement after the switch
integral type
integer or char
literal; symbolic
Each switch case must be labeled by a _______ or _______ constant.
yes (but it must be inside an if or else)
Can there be a break in the middle of a case?
jump out of the switch immediately
What do breaks in the middle of a case tell the program to do?
Is the default clause required?
no (if not specified, the default action is "do nothing")
enumerated data type
defines a list of symbolic values (ex. private enum State {READY, SET, GO};)
READY, SET, and GO
(ex. private enum State {READY, SET, GO};) What are the symbolic values in the enum list (defined by the programmer)?
capital
The name of the enum type usually starts with a _______ letter.
all caps
enum values are often spelled in _______ to make them stand out more.
Where is an enum definition placed?
inside a class outside of any constructor or method
What is the "type-dot" (ex. State.READY) notation used for?
to refer to the symbolic values from the enum list
symbols
The values in an enum list are defined only by their _______; they are not literal strings and they have no numeric values.
an attribute or state
Define an enum type for variables that describe what?
== and != operators
In boolean expressions, how are variables of an enum type compared to each other?
modules
Modular programs divide the program into smaller, more manageable pieces called what?
objects; objects
Object-oriented programs break programs into _______, and _______ into methods
instance methods
Non-static variables are used to represent what?
Return type
Constructors don't have a ...
private
In the spirit of encapsulation, it is common to make fields _______ .
What are "overloaded" methods?
methods within the same class that have the same name but different numbers of, or types of arguments
primitive and reference
What are the 2 types of parameters that may be passed to a method?
0 and null
Default constructors will automatically be initialized to _______ or _______
reference
Objects, when passed as arguments, are passed by _______
What does "short-circuit evaluation" mean for the || operator?
if the first operand is true, the second operand is not evalutated
a || !b
What is the equivalent of !(!a && b)?
class variables
Variables that apply to a class as a whole , rather than a particular object of that class. Declared using the "static" keyword
loops/ iterative statements
tell the program to repeat a fragment of code several times for as long as a certain condition holds
while, for, do-while
Java's three iterative statements
while; flexibility; concise and idiomatic
Any iterative code can be implemented using only the _______ loop. But the other two add _______ and make the code more _______ and _______.
lists or files
Iterations are often used in conjunction with _______ or _______.
where (condition) is any logical expression
general form of the while statement
While Loop
informal name for the while statement
body of the loop
statements within braces of a while statement
T/F: It is important to put a semicolon after while (condition).
false (loop would have no body, only an empty statement; statement1 would be left completely out of the loop)
initialization, test of the condition, change
three elements required in any while loop
testing
[element in a while loop] condition is checked before each pass through the loop; if false, body is not executed, iterations end, and program continues with first statement after the loop
before
In a while loop, the condition is tested _______ each pass through the loop.
not executed at all
If the condition is false at the very beginning of a while loop, the body of the loop is _______ __ _______.
change
[element in a while loop] at least one of the variables tested in the condition must _______ in the loop's body (otherwise the loop will repeat infinitely and program will "hang")
Change of a variable is often implemented with what?
increment/ decrement operators (but it can come from any assignment/ input statement)
make it false (making the program jump to the first statement after the body of the loop)
In a while loop, the tested variables must at some point get values that do what to the condition?
by incrementing i (i++;)
In the sumUpTo method, how is change achieved?
for Loop
What is the shorthand for the while loop?
initialization, condition, and change
The for loop combines what three things into one statement?
}
Define a class called MyClass that extends MySuperclass and implements Yourinterface.
always executed once
In a for loop, initialization is a statement that is _______ before the first pass through the loop.
before each pass
In a for loop, condition is tested _______ _______ through the loop.
at the end of each pass
In a for loop, change is a statement executed __ _______ __ _______ through the loop.
if the body of the loop has only one statement
When can the braces in a for loop be dropped?
easier to add statements to the body of the loop
Why do people like to have braces even around one statement of a for loop?
})
T/F: A variable that controls the for loop can be declared right in the for statement.
syntax error: undefined variable i
What error will you get if you try to do something like System.out.println(i) after a closing brace, if i was defined in a for statement?
How does the do-while loop differ from the while loop?
condition is tested AFTER the body of the loop, ensuring that the program goes through the loop at least once
} while (condition);
general form of a do-while statement
as long as condition remains true
How long does a program repeat the body of a do-while loop?
code is hard to read without them
Should keep the braces in a do-while statement (even if the body of the loop is just one statement) because?
less
Are do-while loops used more or less frequently than while and for loops?
When are do-while loops convenient?
when the variables tested in the condition are calculated/ entered within the body of the loop
how to avoid a do-while loop
use a while loop and initialize the variables in a way that makes the condition true before the first pass through the loop
What does the break command instruct a program to do?
to break out of the loop immediately and go to the first statement after the body of the loop
Break must always appear inside a _______.
conditional (if or else) statement (otherwise you will just break out of the loop on the first iteration)
... etc.)
Another way to break out of the loop (and out of the method) that is not a break is?
...))
nested loop
traversing two-dimensional grids and arrays
Nested loops are convenient for _______ _______?
duplicates
Nested loops are also used for finding _______ in a list.
Goldbach conjecture
conjecture that any even integer greater than or equal to 4 can be represented as a sum of two primes
perfect number
whole number equal to the sum of all of its divisors (including 1, excluding the number itself)
2^(n-1)*(2^n - 1)
If you find a number of the form 2^n - 1 that is a prime, what is an even perfect number?
Mersenne primes
primes that have the form 2^n - 1