QUIZ 

CHAPTER 3

Your Name:


3.1 If we pay one-third of our income in tax after subtracting a rebate, how would this formula for tax be expressed as a Java expression?

(a) 1/3*income - rebate
(b) 1/3 * (income - rebate)
(c) (income - rebate) / 3
(d) income/3 - rebate

3.2 How many stars will this loop display?

for (int star = 9; star < 0; star++)
{ System.out.print('*'); }

(a) 9
(b) 0
(c) 10
(d) 8

3.3 Which for-statement can be used to loop over the decades of the 20th century (i.e. 1900, 1910, . . . , 1990)

(a) for (int year = 1990; year <= 1990; year ++)
(b) for (int year = 1990; year < 2000; year ++)
(c) for (int year = 1990; year <= 1990; year +=10)
(d) for (int year = 1990; year <= 1990; year +10)

3.4 If x is a double and has the value -3.00000000008, what will be printed by System.out.print(x)?

(a) -3.00000000008
(b) -3.0
(c) -3.0E-11
(d) -3.8E-10

3.5 The keyword(s) that every typed method must have is:

(a) void
(b) return
(c) break
(d) public static void

3.6 If we declare String name = "John" , the expression name == "John" will yield false. Why?

(a) should be an = not an ==
(b) name and "John" are different objects
(c) "John" will be automatically packed to eight characters and so have four spaces after it.
(d) there should be parentheses around the expression

3.7 If we want to check that two curio objects a and b have the same name and price, but we do not mind about the description, we could use:

(a) a.name == b.name & a.price == b.price
(b) (a.name == b.name) && (a.price == b.price)
(c) a.name.equals(b.name) && a.price == b.price
(d) a==b & (a.description != b.description || a.description == b.description)

3.8 Given the assignment in the PizzaDelivery1 program time = addTime(time,15) what would it become in the PizzaDelivery2 program when there is a Time class containing an addTime method?

(a) time = Time.addTime (time, 15);
(b) time.addTime(time,15);
(c) time = addtime (15);
(d) time.addTime(15);

3.9 To get a random number between 1 and 6, we would use:

(a) number = Random(6)+1;
(b) number = Math,random(6);
(c) number = (int) (Math.random()*6 + 1);
(d) number = Math.random()*6;

3.10 If we have two integers to return from a method, we can use:

(a) an object as a parameter
(b) an object as a return value
(c) two parameters
(d) answer (a) or (b)