Of course, the program in Segment 494 goes
to a lot of trouble to produce int
values from the characters in a
file, just to display them for you as characters. Accordingly, the next
example uses the int
values to initialize Movie
instances,
each of which becomes the target of the rating
method.
import java.io.*; public class Demonstrate { public static void main(String argv[]) throws IOException { FileInputStream stream = new FileInputStream("input.data"); InputStreamReader reader = new InputStreamReader(stream); StreamTokenizer tokens = new StreamTokenizer(reader); while (tokens.nextToken() != tokens.TT_EOF) { int x = (int) tokens.nval; tokens.nextToken(); int y = (int) tokens.nval; tokens.nextToken(); int z = (int) tokens.nval; Movie m = new Movie(x, y, z); System.out.println("Rating: " + m.rating()); } stream.close(); } }