-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFifo.java
77 lines (71 loc) · 1.93 KB
/
Fifo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package SPOS;
import java.io.*;
import java.util.Scanner;
public class fifo
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int nframe, pointer = 0, h = 0, f = 0,str_len;
int buffer[];
int str[];
int memory_layout[][];
System.out.println("Please enter the number of Frames: ");
nframe = sc.nextInt();
System.out.println("Please enter the length of the Reference string: ");
str_len = sc.nextInt();
str = new int[str_len];
memory_layout = new int[str_len][nframe];
buffer = new int[nframe];
for(int j = 0; j < nframe; j++)
{
buffer[j] = -1;
}
System.out.println("Please enter the reference string: ");
for(int i = 0; i < str_len; i++)
{
str[i] = sc.nextInt();
}
System.out.println();
for(int i = 0; i < str_len; i++)
{
int search = -1;
for(int j = 0; j < nframe; j++)
{
if(buffer[j] == str[i])
{
search = j;
h++;
break;
}
}
if(search == -1)
{
buffer[pointer] = str[i];
f++;
pointer++;
if(pointer == nframe)
{
pointer = 0;
}
}
for(int j = 0; j < nframe; j++)
{
memory_layout[i][j] = buffer[j];
}
}
for(int i = 0; i < nframe; i++)
{
System.out.print("Frame "+(i+1)+":\t\t");
for(int j = 0; j < str_len; j++)
{
System.out.print(memory_layout[j][i]+"\t");
}
System.out.println();
}
System.out.println("The number of Faults: " + f);
System.out.println("The number of Hits: " + h);
System.out.println("Hit Ratio: " +(float)((float)h/str_len));
sc.close();
}
}