<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">import java.util.Enumeration;

public class ExamplePageManager extends PageManager {
    /* Example Info Object. */
    private class MyInfo extends Info {
		public int numAccesses;
	
		public MyInfo (int page) {
			numAccesses = 0;
			pageNumber = page;
		}
    }

    public ExamplePageManager (int numPages) {
		super (numPages);
    }

    /* This page manager replaces a page at specific frame in the memory during a page fault. 
     */
    public final void handlePageFault (int page, MemoryInterface memoryInterface) {
		MyInfo newInfo = new MyInfo(page);

		System.out.println("Page fault for page "+page+".");

		/* Memory is not full. */
		if (memoryInterface.map(newInfo)) {
			System.out.println("Inserted page "+page+" in memory.\n");
			return;
		}
    
		/* Use 'mod' operator to determine which frame to swap. */
		Enumeration map = memoryInterface.getMap();
		for (int i=0; i&lt;(page%memoryInterface.numPages()); i++) {
			map.nextElement();
		}
		MyInfo oldInfo = (MyInfo)map.nextElement();

		memoryInterface.swap(oldInfo.pageNumber, newInfo);
	
		System.out.println("Swapped old page "+oldInfo.pageNumber+" with new page "+page+".");
		System.out.println("Old page was accessed "+oldInfo.numAccesses+" times.\n");
    }

    public final void handlePageReference (int page, MemoryInterface memoryInterface) {
		MyInfo myInfo  = (MyInfo)memoryInterface.getInfo(page);
		myInfo.numAccesses++;
    }
}
</pre></body></html>