Question
Java program that implements the FIFO and LRU page replacement algorithms in the way that we discussed them in class. Ask the user for a
Java program that implements the FIFO and LRU page replacement algorithms in the way that we discussed them in class.
Ask the user for a 14-digit reference string consisting of the digits from 0-7. They can be any random digits from 0-7, not all the digits need to be included, and they can be in any order. Here's an example of one such string for you to use 0 1 3 0 2 1 4 2 3 6 5 1 6 0. Note that the data type for this could be either String or int (an array would likely be helpful here).
Randomly set the number of frames from the range 1 - 5, inclusive (Hint: use Java's built in Random class).
Display the number of page faults for each algorithm.
Some hints:
- The reference string can either be String or int. It seemed easier to store the values into an array.
- Start with a number that you know first. For example, using the example reference string given above, I used 3 frames to test it. I did it on paper first and then checked it against what the program output. As you'll see in the example below, for testing purposes, I had it print out the frames as it went through. Once you have it working for the hardcoded number of frames, randomize it and see if your code works for other frames.
- Your code should be able to work with other reference strings and number of frames.
- An ArrayList seems to be good for representing a frame since you can insert at the front.
- Your algorithm is important. Start out by writing your set of steps in your java application as comments. I would prefer you give me just a file that has nothing but comments in it than for you to copy something that you don't understand from the internet.
Here's some sample output (user input in bold):
Please enter a 14 digit reference string containing only the digits 0-7, in any order: 01302142365160 Reference String: 0 1 3 0 2 1 4 2 3 6 5 1 6 0 Frame state: [0] 1 faults Frame state: [1, 0] 2 faults Frame state: [3, 1, 0] 3 faults Frame state: [3, 1, 0] 3 faults Frame state: [2, 3, 1] 4 faults Frame state: [2, 3, 1] 4 faults Frame state: [4, 2, 3] 5 faults Frame state: [4, 2, 3] 5 faults Frame state: [4, 2, 3] 5 faults Frame state: [6, 4, 2] 6 faults Frame state: [5, 6, 4] 7 faults Frame state: [1, 5, 6] 8 faults Frame state: [1, 5, 6] 8 faults Frame state: [0, 1, 5] 9 faults Number of page faults with 3 frames for FIFO: 9 Frame state: [0] 1 faults Frame state: [1, 0] 2 faults Frame state: [3, 1, 0] 3 faults Frame state: [0, 3, 1] 3 faults Frame state: [2, 0, 3] 4 faults Frame state: [1, 2, 0] 5 faults Frame state: [4, 1, 2] 6 faults Frame state: [2, 4, 1] 6 faults Frame state: [3, 2, 4] 7 faults Frame state: [6, 3, 2] 8 faults Frame state: [5, 6, 3] 9 faults Frame state: [1, 5, 6] 10 faults Frame state: [6, 1, 5] 10 faults Frame state: [0, 6, 1] 11 faults Number of page faults with 3 frames for LRU: 11
Note that the above output uses a String as the data type for the reference string. To use an int, consider adding spaces between the digits (0 1 3 0 2 1 4 2 3 6 5 1 6 0).
Only the total number of page faults for each algorithm is necessary. The other output I have here (i.e., frame state) was simply for debugging purposes
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started