Finally, you can use the three
successive numbers read from each line of text to construct a movie. Then,
you can report the movie's rating, using, for example, the Movie
class definition provided in Segment 316:
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); BufferedReader buffer = new BufferedReader(reader); String line; while ((line = buffer.readLine()) != null && !line.equals("")) { line = line.trim(); int nextSpace = line.indexOf(" "); int x = Integer.parseInt(line.substring(0, nextSpace)); line = line.substring(nextSpace).trim(); nextSpace = line.indexOf(" "); int y = Integer.parseInt(line.substring(0, nextSpace)); line = line.substring(nextSpace).trim(); int z = Integer.parseInt(line); Movie m = new Movie(x, y, z); System.out.println("Rating: " + m.rating()); } stream.close(); return; } } --- Data --- 4 7 3 8 8 7 2 10 5 --- Result --- Rating: 14 Rating: 23 Rating: 17