Practice exam 1
Written Portion of Exam 1 - Sample
3. (10 points) Provide a concrete example of each of the following (in Java). If appropriate, you may use the same example more than once.
4. (10 points) Provide a concise comparison of the two terms in each of the following.
5. (5 points) Write a single statement for each of the following that:
Answer all of the following questions. This is a "closed book" examination and you must work entirely on your own.
-
- (10 points) Choose the best answer to each of the following:
(1) _____
In Java, +
is- A relational operator
- A unary operator
- A mathematical operator
- All of the above
- None of the above
(2) _____
In Java, -1 the - is - A unary operator
- A binary operator
- Has
boolean
operands - All of the above
- None of the above
(3) _____
In Java, a variable is - The implicit loss of precision in arithemtic operations
- The way the decrement operator changes
- A named space for holding a value
- All of the above
- None of the above
(4) _____
In Java, the statement doubl cost;
- Will cause a compile-time error
- Will cause a run-time error
- Will cause a repetitive stress error
- All of the above
- None of the above
(5) _____
In the Java statement i = (int)d;
the operator=
is a/an:- Assignment operator
- Relational operator
- Typecast operator
- All of the above
- None of the above
(6) _____
In the Java statement i = (int)d;
the(int)
operator is a/an:- Assignment operator
- Relational operator
- Typecast operator
- All of the above
- None of the above
(7) _____
In the Java statement i = (int)4.0;
the operand of the(int)
operator is a/an:- Assignment operator
- Literal
- Typecast operator
- All of the above
- None of the above
(8) _____
In Java, what kind of statement is int i;
?- Assignment statement
- Declaration statement
- Typecast statement
- All of the above
- None of the above
(9) _____
In Java, an assignment
statement must contain which of the following?- Curly brackets
- Parentheses
- An equal sign
- All of the above
- None of the above
(10) _____
In Java, the main()
method of the "main class" must have what return type?double
int
String
void
- None of the above
- (10 points) Choose the best answer to each of the following:
3 * 4 * 2 |
|
3 * 4 + |
|
2 + 3 + 4 * 5 |
|
2 + 3 +* 4 * 5 |
|
Compile-time error |
|
Logic error |
|
Run-time error |
|
Style error |
|
Syntax error |
|
Actual parameters and formal parameters |
|
Declaration and assignment |
|
double and int |
|
Reference type and value type |
|
Class and method |
|
Declares price to be a double variable. |
|
Assigns the value 40.99 to a previously declared double variable named price . |
|
Reduces a previously declared double variable named price by 10 percent. |
|
Assigns the result of a call to a static method named salesTax() (that is passed a previously declared double actual parameter named price ) in the Accounting class to a previously declared double variable named tax . |
|
Displays the value of a previously declared double variable named tax on the console (i.e., standard output) in a field that has a width of 6 with 2 digits to the right of the decimal place. |
|
6. (5 points) Show what will be printed by the following application (assuming it is compiled and executed properly).
public class CardChecker{ public static void main(String[] args) { int digit2; ing digit3; int group1; int group2; int group3; int group4; group1 = 6271; group2 = 1882; group3 = 4132; group4 = 71; if (checkGroup(group1)) { System.out.printf("Step A\n"); } digit2 = getDigit(group2); if (digit2 > 1) {
System.out.printf("Step B\n"); } digit3 = getDigit(group3); if (digit2 == digit3) { System.out.printf("Step C\n"); } if (group1 > group2) { if (group4 > 100) { System.out.printf("Step D\n"); } } else { System.out.printf("Step E\n"); } } public static int getDigit(int n) { int result; result = n / 1000; return result; } public static boolean checkGroup(int n) { boolean result; int remainder; remainder = n % 2; result = (remainder == 1); return result; } }