Programming and Problem Solving with Java

(やまだぃちぅ) #1

258


11.What kind of loop would you use in an application that reads the closing price
of a stock for each day of the week? (pp. 233–236)
12.How would you extend the loop in Question 11 to make it read prices for 52
weeks? (pp. 236–242)
13.What distinguishes a mutable object from an immutable object? (pp. 242–245)
14.Describe the data sets you would use to test an EOF-controlled loop that
averages test scores. (pp. 252–255)

Answers
1.No. File input is more appropriate for applications that input large amounts of data.
2.The constructor associates the name of the disk file with the file variable used in the code, and places the
file pointer at the first piece of data in the file.
3.W88 What comes next?
4.number = Integer.parseInt(infile.readLine());
5.while( !done )6.The process being repeated, plus initializing, testing, and incrementing the loop control
variable 7.Yes 8.The flag is set outside the loop; the expression checks the flag; and an ifinside the loop re-
sets the flag when the termination condition occurs.9.A counting operation increments by a fixed value
with each iteration of the loop; a summing operation adds unknown values to the total.10.A loop control
variable controls the loop; an event counter simply counts certain events during execution of the loop.11.
Because there are five days in a business week, you would use a count-controlled loop that runs from 1 to 5.
12.Nest the original loop inside a count-controlled loop that runs from 1 to 52.13.The state of a mutable ob-
ject can be changed after instantiation; an immutable object cannot be changed.14.Normal data, data with
erroneous values such as negative test scores, a set with a single input value, and an empty file

Exam Preparation Exercises


1.What are the five steps in using file input?
2.What is the meaning of the argument to the constructor for file types
FileReaderand FileWriter?
3.Where should the file declarations and the calls to the appropriate
constructors be placed in an application? Why?
4.What does the following statement do?

inFile.skip(1000L);
5.What does the readLinemethod for the class BufferedReaderreturn?


  1. a.What value does the readLinemethod return at end-of-file?
    b.Does the readLinemethod include the newline character in its return value?
    c. Distinguish between a nullvalue and an empty string.
    7.Explain the difference between a loop and a branch.
    8.What does the following loop print out? (numberis of type int.)


number = 1 ;
while(number < 11 )
Free download pdf