Design and implement a Demand Paging virtual memory simulator! It must be a text
ID: 3556380 • Letter: D
Question
Design and implement a Demand Paging virtual memory simulator!
It must be a text based application (NOT a GUI based one).
You can use the Java programming language.
The following algorithms must be implemented: FIFO, OPT, LRU and LFU.
The application must simulate the execution of each of these algorithms on a hypothetical computer having only N physical frames (numbered from 0 to N-1, N<8), assuming that the single process that is running has a virtual memory of ten frames (numbered from 0 to 9). The number N should be a number provided in the command line as an argument.
The algorithms will be simulated based on a reference string (a sequence of pages that are to be accessed) that will be either read from the keyboard or randomly generated.
THE SIMULATION MUST FOLLOW THE ANIMATED EXAMPLES FROM THE ONLINE MODULE 3 AS CLOSE AS POSSIBLE IN ALL ASPECTS !!!
The program should be menu-based and the menu will keep the user in a loop containing the following options:
0
Explanation / Answer
package simulator;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
public class Menu {
private int selected; //stores the menu selection
private boolean showReferenceString;
public String selectedReferenceStringBuffer;
static final String VFRAMES = "01234567";
static Random rnd = new Random();
// does the whole menu logic (presentation, validation and returns reult)
public int doMenu() {
this.showMenu();
int token;
do {
Scanner scanner = new Scanner(System.in);
// non integers shouldn't be accespted
while (!scanner.hasNextInt()) {
System.out.print(" Valid selections are 0-6 (try again)> ");
scanner.nextLine();
}
token = scanner.nextInt();
//other integers shouldn't work
if (token > 6 || token < 0) {
System.out.print(" Seriously? you can choose either 0,1,2,3,4,5 or 6. Everything else just ain't gonna work. (try again) > ");
}
} while (token > 6 || token < 0);
this.selected = token;
// return the valid selection to caller
return this.selected;
}
//menu view
public void showMenu() {
String menu = "Memory Paging Simulation Menu: ";
// display the reference string if display is true
if (this.showReferenceString) {
menu += "[Current RS:" + this.selectedReferenceStringBuffer + "] ";
}
menu += "0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.