Write a program called PageReplacement that implements the FIFO, LRU, and optimal page-replacement algorithms for demand paging. Allow the user to pass in the number of frames and a page reference string on the command line e.g. java PageReplacement 4 13603449450175909982. If the number of frames is 0, the program should simulate all possible number of frames 1 through 9. The values in the page reference string should be between 0 and 9 inclusive.
If there are no arguments, ask the user for the number of frames and the length of the page reference string and generate a random page-reference string, Apply the same page-reference string to each algorithm and record the number of page faults incurred by each algorithm.
You may write your program in either C, C++, Java, or Python.
You may use AI to help with minor details, but you should design and organize the program yourself. Most of the code should ultimately be your own creation.
Your program does not have to look exactly (or anything) like this. If nothing else, this can give you a sample request queue to test.
Number of frames between 1 and 9 (0 to try all of them): 0
Number of page requests to simulate between 1 and 100: 20
Requests: [5, 8, 4, 3, 2, 4, 2, 9, 3, 8, 7, 6, 1, 9, 7, 3, 3, 3, 0, 4]
FIFOReplacement: frames: 1, faults: 18
FIFOReplacement: frames: 2, faults: 17
FIFOReplacement: frames: 3, faults: 15
FIFOReplacement: frames: 4, faults: 14
FIFOReplacement: frames: 5, faults: 12
FIFOReplacement: frames: 6, faults: 11
FIFOReplacement: frames: 7, faults: 11
FIFOReplacement: frames: 8, faults: 10
FIFOReplacement: frames: 9, faults: 10
-----------------
LRUReplacement: frames: 1, faults: 18
LRUReplacement: frames: 2, faults: 17
LRUReplacement: frames: 3, faults: 16
LRUReplacement: frames: 4, faults: 14
LRUReplacement: frames: 5, faults: 13
LRUReplacement: frames: 6, faults: 11
LRUReplacement: frames: 7, faults: 11
LRUReplacement: frames: 8, faults: 11
LRUReplacement: frames: 9, faults: 10
-----------------
OptimalReplacement: frames: 1, faults: 18
OptimalReplacement: frames: 2, faults: 15
OptimalReplacement: frames: 3, faults: 13
OptimalReplacement: frames: 4, faults: 11
OptimalReplacement: frames: 5, faults: 10
OptimalReplacement: frames: 6, faults: 10
OptimalReplacement: frames: 7, faults: 10
OptimalReplacement: frames: 8, faults: 10
OptimalReplacement: frames: 9, faults: 10
-----------------