CS300 EXAMName: ______

By signing I agree to abide by the UWA policies governing academic integrity.

1. For execution, Java Programs are
(a) Compiled
(b) Interpreted
(c) All of the above
(d) None of the above

2. Java data types are called
(a) Primitives
(b) Objects
(c) All of the above
(d) None of the above

3. Java was first released
(a) In the 1970's
(b) In the 1980's
(c) In the 1990's
(d) In 2001

4. The inventor of Java, James Gosling, worked for
(a) IBM
(b) Apple
(c) MicroSoft
(d) Sun Microsystems

5. The Java language is based on
(a) BCPL
(b) C
(c) Pascal
(d) Basic

6. This company popularized personal computing
(a) IBM
(b) Apple
(c) Microsoft
(d) Sun Microsystems

7. This company made personal computing legitimate for business and industry use
(a) IBM
(b) Apple
(c) Microsoft
(d) Sun Microsystems

8. The Java Development kit we want to use is
(a) Java ME JDK 1.4
(b) Java EE JDK 1.4
(c) Java EE JDK 1.7
(d) Java SE JDK 1.7

9. Compute: 5 + 6 * 10 % 4 = ?
(a) 1
(b) 2
(c) 5
(d) 17

10. Compute: 6 + 6 * 5 % 3
(a) 0
(b) 6
(c) 18
(d) None of the above

11. Compute: 4 * 2 - 8 / 5 = ?
(a) 0
(b) 4
(c) 7
(d) -19

12. Explain the value of Math.random();
(a) There is no such thing.
(b) Returns an int value that can represent dice or cards.
(c) Returns a double value between 0 and Double.MAX_VALUE
(d) Returns a number between 0 and 1.

1. Compute: 4 + 2 * 5 % 3 = ?
(a) 0
(b) 2
(c) 5
(d) 8

2. Compute: 3 + 2 % 4 * 5
(a) 0
(b) 5
(c) 13
(d) None of the above

3. Compute: 3 * 6 - 5 / 2 = ?
(a) 1
(b) 6
(c) 8
(d) 16

4. In the following code snippit
while (isLooping) {
...
}
the variable type of isLooping must be
(a) boolean
(b) double
(c) integer
(d) String

5. while loop repetitions can be controlled using a counter or a ___
(a) clock
(b) sentinel
(c) table
(d) timer

6. The expression x = x + 6 can be abbreviated
(a) +x = 6;
(b) x =+ 6;
(c) x ++ 6;
(d) x += 6;

7. The expression y = y * 3 can be abbreviated
(a) *y = 3;
(b) y ** 3;
(c) y *= 3;
(d) y =* 3;

8. What is the value of p?
int n = 3;
int p = 5 * ++n;
(a) 5
(b) 15
(c) 18
(d) 20

9. What is the value of q?
int m = 2;
int q = 5 * m++;
(a) 5
(b) 10
(c) 11
(d) 15

10. Two methods, having the same name but different arguments, are said to be
(a) overconfident
(b) overestimated
(c) overloaded
(d) overworked

11. The keyword void is used to indicate
(a) a blank String value
(b) a function has no return value
(c) a null or nothing value
(d) an unbound type

12. When assigning or casting a floating point decimal value to an int value
(a) a warning is generated
(b) an error is generated
(c) the decimal number is rounded
(d) the decimal number is truncated

0.9 + 4 * 5 % 6 = ?
(a.) 5
(b.) 11
(c.) 29
(d.) 65

1.7 + 4 % 12 * 4 = ?
(a.) 10
(b.) 11
(c.) 23
(d.) 44

2.3 - 11 / 3 * 9 = ?
(a.) -24
(b.) -18
(c.) 0
(d.) 3

3.5 - 12 % 9 + 7 = ?
(a.) -8
(b.) -7
(c.) 0
(d.) 9

4.12 * 4 - 11 / 7 = ?
(a.) -12
(b.) 5
(c.) 36
(d.) 47

5.11 * 12 % 4 * 7 = ?
(a.) -1
(b.) 0
(c.) 1
(d.) 20

6.5 / 10 + 6 / 12 = ?
(a.) -1
(b.) 0
(c.) 1
(d.) 2

7.5 / 8 * 4 + 9 = ?
(a.) -1
(b.) 0
(c.) 8
(d.) 9

8.12 % 3 + 3 * 8 = ?
(a.) 0
(b.) 12
(c.) 24
(d.) 48

9.8 % 12 * 11 / 4 = ?
(a.) 2
(b.) 8
(c.) 9
(d.) 22

10. What is the value of p?
int n = 4;
int p = 6 / --n;
(a.) 0
(b.) 1
(c.) 2
(d.) This is an error

11. What is the value of q?
int m = 3;
int q = 9 / m--;
(a.) 3
(b.) 4
(c.) 5
(d.) This is an error

For the following assume:
int a = 8;
int b = 3;
int c = 7;

0.12 + a * a % 10 = ?
(a.) 0
(b.) 16
(c.) 76
(d.) 160

1.12 + b % 9 * b = ?
(a.) 14
(b.) 15
(c.) 18
(d.) 21

2.12 - c / 4 * 11 = ?
(a.) 0
(b.) 1
(c.) 11
(d.) 12

3.5 - c % 11 + b = ?
(a.) -3
(b.) -2
(c.) 0
(d.) 1

4. The parameter weekday is true if it is a weekday, and the parameter vacation is true if we are on vacation. We sleep in if it is not a weekday or we're on vacation. Return true if we sleep in.
sleepIn(false, false) → true
sleepIn(true, false) → false
sleepIn(false, true) → true
public booleansleepIn(boolean weekday, boolean vacation) {
}

5. We have two monkeys, a and b, and the parameters aSmile and bSmile indicate if each is smiling. We are in trouble if they are both smiling or if neither of them is smiling. Return true if we are in trouble.
monkeyTrouble(true, true) → true
monkeyTrouble(false, false) → true
monkeyTrouble(true, false) → false
public booleanmonkeyTrouble(booleanaSmile, booleanbSmile) {
}

6. Given two int values, return their sum. Unless the two values are the same, then return double their sum.
sumDouble(1, 2) → 3
sumDouble(3, 2) → 5
sumDouble(2, 2) → 8
public intsumDouble(int a, int b) {
}

For the following assume:
int a = 6;
int b = 5;
int c = 4;
int d = 3;

0.12 % d + d * 8 = ?
(a.) 0
(b.) 12
(c.) 24
(d.) 48

1.b / 8 * c + 9 = ?
(a.) -1
(b.) 0
(c.) 8
(d.) 9

2.9 + c * b % a = ?
(a.) 5
(b.) 11
(c.) 29
(d.) 65

3.b / 10 + a / 12 = ?
(a.) -1
(b.) 0
(c.) 1
(d.) 2

4.We have a loud talking parrot. The "hour" parameter is the current hour time in the range 0..23. We are in trouble if the parrot is talking and the hour is before 7 or after 20. Return true if we are in trouble.
parrotTrouble(true, 6) → true
parrotTrouble(true, 7) → false
parrotTrouble(false, 6) → false
public booleanparrotTrouble(boolean talking, int hour) {
}

5. Given 2 ints, a and b, return true if one if them is 10 or if their sum is 10.
makes10(9, 10) → true
makes10(9, 9) → false
makes10(1, 9) → true
public boolean makes10(int a, int b) {
}

6. Given 2 int values, return true if one is negative and one is positive. Except if the parameter "negative" is true, then return true only if both are negative.
posNeg(1, -1, false) → true
posNeg(-1, 1, false) → true
posNeg(-4, -5, true) → true
public booleanposNeg(int a, int b, boolean negative) {
}

We are having a party with amounts of tea and candy. Return the int outcome of the party encoded as 0=bad, 1=good, or 2=great. A party is good (1) if both tea and candy are at least 5. However, if either tea or candy is at least double the amount of the other one, the party is great (2). However, in all cases, if either tea or candy is less than 5, the party is always bad (0).
teaParty(6, 8) → 1
teaParty(3, 8) → 0
teaParty(20, 6) → 2
public intteaParty(int tea, int candy) {
}

The squirrels in Palo Alto spend most of the day playing. In particular, they play if the temperature is between 60 and 90 (inclusive). Unless it is summer, then the upper limit is 100 instead of 90. Given an int temperature and a booleanisSummer, return true if the squirrels play and false otherwise.
squirrelPlay(70, false) → true
squirrelPlay(95, false) → false
squirrelPlay(95, true) → true
public booleansquirrelPlay(int temp, booleanisSummer) {
}

Given 2 positive int values, return the larger value that is in the range 10..20 inclusive, or return 0 if neither is in that range.
max1020(11, 19) → 19
max1020(19, 11) → 19
max1020(11, 9) → 11
public int max1020(int a, int b) {
}

Given two temperatures, return true if one is less than 0 and the other is greater than 100.
icyHot(120, -1) → true
icyHot(-1, 120) → true
icyHot(2, 120) → false
public booleanicyHot(int temp1, int temp2) {
}

1. Tracing. Show the output of the following code as closely as possible:

inti = 0;
System.out.println(i);
while (i < 10){
System.out.print(++i);
System.out.print(i++);
System.out.print(++i);
System.out.print(i++);
System.out.println();
}
System.out.println(i);

2. Tracing. Show the output of the following code as closely as possible:
int a = 5;
int b = 8;
if ( a < b ){
System.out.format("1st Answer: %10d%n", a*b);
}
else if ( a == b ){
System.out.format("2nd Answer: %5d%n", b/a);
}
System.out.format("3rd Answer: %d%n",a%b);

3. Tracing. Show the output of the following code as closely as possible:
int k = 3;
System.out.println(k);
while (k --> 0){
System.out.println(k);
}
System.out.println(k);

4. Tracing. Show the output of the following code as closely as possible:
int b = 37;
int c = 0;
while (b > 0) {
c++;
if (b % 2 != 0) {
System.out.print( 1 );
}
else {
System.out.print( 0 );
}
b /= 2;
}
while (c < 8) {
c++;
System.out.print( 0 );
}

True or False.

Let:

boolean A = true;

boolean B = true;

boolean C = false;

boolean D = false;

boolean E = true;

int K = 8;

int L = 12;

int M = 4;

int N = 9;

double F = 7.5;

double G = 3.01;

double H = 10.2;

Compute the value of answer for each of the following statements.

0. answer = A & B || C & D & E;

1. answer = A || B & C || D & E;

2. answer = A || B || C || D & E;

3. answer = A & B & C & D || E;

4. answer = A & K < L || M < N || E;

5. answer = B & L > M & N < K || D;

6. answer = C & F > G || H > F || C;

7. answer = D || K > L & M < N & C;

8. answer = C || L < M || N < K & D;

9 answer = B || F < G & H > F & E;

10. Place these operators in order from highest precedence to lowest precedence level.

=

==

++

%

!

||

+