Your Name:

4.1 The statement for connecting to the keyboard is

(a) Stream in = System.in;
(b) Stream in = new Stream(System.in);
(c) Stream in = Stream (System.in);
(d) Stream System.in = new Stream(System.in);

4.2 We have a display set-up, and a box called "File name" in the input section. Why does display.getString(filename) give the message ERROR: No such input label:?

(a) filename should be in quotes
(b) the method is readString, not getString
(c) we must press the Ready bar first
(d) getString needs the exact box name, i.e."File Name"

4.3 For PC users: if the Stream class has been compiled in a directory called C:\Book\ JG\javagently what should be put in the classpath to get access to Stream?

(a) Stream.class
(b) C:\Book\JG\javagently\
(c) C:\Book\JG\
(d) C:\

4.4 From a sequence of numbers coming in, we want to write out only those between 30 and 40. What would be the correct if-statement to control this process?

(a) if (number >=30 & <= 40)
(b) if (number >=30 | number < 40)
(c) if (30 <= number >= 40)
(d) if (number >= 30 & number <= 40)

4.5 The program using the Stream class is expecting three integers to be read from a file into the variables a, b and c, what will happen if b is a string in error, given the data 45 2r3 67 84?

(a) a=45 b=67 c=84
(b) a=45 b=23 c=67
(c) a=45 b=undefined c=67
(d) a=45 program crashes

4.6 The program using the Display class has three integer boxes with values 45 67 84. The ready bar is pressed and then the first value is changed by the user to 55. Three getInteger calls then follow. What will be the values of the three integers?

(a) 55 67 84
(b) 45 67 84
(c) error 67 84
(d) 45 55 67

4.7 We wish to read all the numbers off a file and there are 210 of them. If we specify a try-for loop as

try {
for (int i = 0 ; i <=10; i++)
{ ... int n = in.getInteger(); }
catch (EOFException e) { }

how many numbers get read?
(a) 200
(b) 210
(c) 10
(d) none

4.8 The correct statement for gaining access to Java's input-output classes is

(a) import java.io;
(b) import java.io.*;
(c) package java.io;
(d) import javagently.*;

4.9 If x is 456.23458 then what will display.println(Stream.format(x,4,2)) give (if _ is a space)?

(a) _456.23
(b) 456.23
(c) 456.2
(d) 456.

4.10 In Figure 4.7, the Stream class has two methods called format. These are not shown in Stream objects such as in and fin because:

(a) they are static
(b) they have the same name
(c) it saves space in the diagram
(d) they need other classes in javagently