Question

Java Looking for some help on getting this started. Directions below. Operating systems designers have long...

Java

Looking for some help on getting this started. Directions below.

Operating systems designers have long used simulation as an inexpensive way to test new algorithms. In this assignment you write a Java program that prompts the user for simulation data then runs a selected page replacement algorithm on that system, reporting frame assignments and total page faults.

Instructions

Your program will prompt the user first for the number of frames to be used in the simulation, then for a page access string, where page numbers (positive) are separated by one or more spaces. Reprompt on invalid input.

Please enter the number of frames: abc
Please enter the number of frames: 5
Please enter the page reference string: 1 2 1 4 3 6 3 4 5 1 2 8 6 7 2 5 3 4 1 7 8

Next, prompt the user to select one of 3 page replacement algorithms: FIFO, Optimal, or LRU

Please enter 1. for FIFO, 2. for Optimal, or 3. for LRU: 1

Finally assuming pure demand paging show the page to frame mapping for each page fault, and count the total number of page faults.

1 -> 1
2 -> 2
4 -> 3
3 -> 4
6 -> 5
5 -> 1
1 -> 2
2 -> 3
8 -> 4
7 -> 5
3 -> 1
4 -> 2
12 page faults.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

java code:

import java.util.*;
public class Main
{
   public static void main(String[] args) throws java.util.InputMismatchException
   {

int j,i,k,no,count=0;
int a[]=new int[100];
int frame[]=new int[10];
int pos,value, n;
Scanner s=new Scanner(System.in);
  
  
System.out.println("enter number for pages:");
n=s.nextInt();
System.out.println("enter page numbers:\n");
for(i=0;i<n;i++)
{
a[i]=s.nextInt();
}

System.out.println("enter no for frames:\n");
no=s.nextInt();
for(i=0;i<no;i++)
frame[i]=-1;
if(no==(int)no)
{
  
j=0;
pos=0;
value=a[j];
while(j<n)
{
for(i=0;i<no;i++)
{
if(frame[i]==value)
{
j++;
break;
}
if(i==2)
{
frame[pos]=value;
j++;
pos++;
for(i=0;i<no;i++)
{
System.out.print(" \t"+frame[i]);
}
count++;
System.out.println("\n");
}
if(pos==no)
{
pos=0;
}
}
value=a[j];
}
}
else
System.out.println("invaild input:");
  

System.out.println(" page defaults are:"+count);
  

   }
}

output:

Add a comment
Know the answer?
Add Answer to:
Java Looking for some help on getting this started. Directions below. Operating systems designers have long...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This is JAVA programing problem. Please give me all necessary screenshot and comments. (I use Ecl...

    This is JAVA programing problem. Please give me all necessary screenshot and comments. (I use Eclipse) Thanks Write a program that implements the FIFO, LRU, and Optimal page replacement algorithms presented in chapter 8 of your text. First generate a random page-reference string (this should be 20 entries long) where page numbers range from 0 to 9. Apply the random page-reference string to each algorithm, and record the number of page faults incurred by each algorithm. Implement the replacement algorithms...

  • Consider the following page reference string: 1, 0, 3, 2, 6, 4, 5, 0, 1, 7,...

    Consider the following page reference string: 1, 0, 3, 2, 6, 4, 5, 0, 1, 7, 7, 6, 4, 3, 5, 2, 1, 3, 2, 7 Assuming demand paging with three frames, how many page faults would occur for the following replacement algorithms? Show your work. (a) LRU replacement (b) FIFO replacement (c) Optimal replacement

  • Consider the following page reference string: 5, 3,7,5, 3, 6, 1, 0,4,6,2,0,1,2,7,3,1,4,7,2 Assuming demand paging with...

    Consider the following page reference string: 5, 3,7,5, 3, 6, 1, 0,4,6,2,0,1,2,7,3,1,4,7,2 Assuming demand paging with three frames, how many page faults would occur for the following replacement algorithms!? LRU replacement FIFO replacement Optimal replacement

  • 9.3 (3 points for correct answer, 7 points for steps) Consider the following page reference string:...

    9.3 (3 points for correct answer, 7 points for steps) Consider the following page reference string: 6, 1, 5, 5, 4, 6, 2, 6, 0 , 1, 7, 2, 3, 1, 4, 6, 7, 2, 5, 2,. Assuming demand paging with three frames, how many page faults would occur for the following replacement algorithms? • LRU replacement • FIFO replacement • Optimal replacement

  • Consider the following page reference string for a specific process: 7, 2, 3, 1, 2, 5,...

    Consider the following page reference string for a specific process: 7, 2, 3, 1, 2, 5, 3, 4, 6, 7, 7, 1, 0, 5, 4, 6, 2, 3, 0, 1 Assuming demand paging with 3 frames, determine the page fault rate for each of the following page replacement algorithms: a. LRU replacement b. FIFO replacement c. Optimal replacement

  • Question 7 30 pts Consider the following page reference string: {1,2,3,4,1,5,6,2,1,2,3,7,6,3} Assume that the system has...

    Question 7 30 pts Consider the following page reference string: {1,2,3,4,1,5,6,2,1,2,3,7,6,3} Assume that the system has 4 page frames allocated to these 7 pages. Follow the page placement and replacement using the following three replacement algorithms: • LRU replacement • FIFO replacement • Optimal replacement How many page faults will occur for these three algorithms? Assume that all frames are initially empty, so your first unique pages will all cost one fault each USE ENCLOSED TABLES! Show all calculations in...

  • Answer the following questions based on the Memory Management tasks of an Operating System. 5 Consider...

    Answer the following questions based on the Memory Management tasks of an Operating System. 5 Consider the following sequence of page references: 5, 6, 7, 6, 8, 7, 9, 5, 9, 6, 8, 9 Assuming that all frames are initially empty, indicate the contents of memory after each reference, and how many page faults are found for each of the following page replacement algorithms: First In First Out (FIFO):                                   [2 .5 M]                                               Reference String 5 6 7 6 8 7...

  • Consider the following page reference string:

    4, 6, 7, 8, 6, 7, 8, 4, 6, 4, 4, 7, 5, 8Assuming demand paging with three frames, how many page faults would occur for the following replacement algorithms? illustrate your work.                            i.          FIFO replacement.                           ii.          LRU replacement.

  • Consider the following page reference string: 1, 2, 3, 4, 2, 1, 5, 6, 2, 1,...

    Consider the following page reference string: 1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6. How many page faults would occur for the following replacement algorithms, assuming one, two, three, four, five, six, or seven frames? Remember all frames are initially empty, so your first unique pages will all cost one fault each. • LRU replacement • FIFO replacement • Optimal replacement

  • Consider the following page reference string for a three-frame memory: 6 3 1 5 3 4...

    Consider the following page reference string for a three-frame memory: 6 3 1 5 3 4 3 2 5 4 3 4 5 1 5 3 1 6 3 1 Apply LRU, Clock and FIFO algorithms What will be the number of page faults for each replacement algorithm note that page faults at the beginning are counted?

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT