import java.util.Scanner; import java.util.LinkedList; import java.util.ListIterator; import java.io.IOException; import java.io.FileInputStream; /** Program.java -- This file reads input for the cache simulation. * Actually it's NOT a real program. We just want a list of memory addresses * that are referenced dynamically when a program executes. I'm simply * calling this the "program" class so that you see that the cache is * running data from a program. * Let's use a LinkedList of String (the lines of input containing addresses). */ public class Program { private LinkedList address; // Constructor for "program" class. // The purpose of the counter variable is to allow us to keep track // of which number to fetch while the simulation is running. public Program() throws IOException { address = new LinkedList(); Scanner kbd = new Scanner(System.in); System.out.printf("What is the name of the input file? "); String fileName = kbd.nextLine().trim(); Scanner in = new Scanner(new FileInputStream(fileName)); while(in.hasNextLine()) { String line = in.nextLine(); address.add(line); } } // Give us a way to traverse the list of addresses from the beginning. public ListIterator listIterator() { return address.listIterator(0); } }