-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab5.java
63 lines (52 loc) · 1.46 KB
/
lab5.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
import java.io.*;
import java.util.*;
class lab5
{
public static int lineNum = 0;
private static void processLine(String line, ArrayList<Cache> caches)
{
// calculate and mod tag for all caches
for (Cache cache : caches)
{
cache.update(line);
}
}
private static void printCaches(ArrayList<Cache> caches)
{
// print each cache in order
for (Cache cache : caches)
{
cache.printCache();
}
}
private static void initCaches(ArrayList<Cache> caches)
{
caches.add(new Cache(1, 1, 2048, 1));
caches.add(new Cache(1, 2, 2048, 2));
caches.add(new Cache(1, 3, 2048, 4));
caches.add(new Cache(2, 4, 2048, 1));
caches.add(new Cache(4, 5, 2048, 1));
caches.add(new Cache(4, 6, 2048, 4));
caches.add(new Cache(1, 7, 4096, 1));
}
public static void main(String[] args)
{
try
{
File file = new File(args[0]);
Scanner scanner = new Scanner(file);
ArrayList<Cache> caches = new ArrayList<Cache>();
initCaches(caches);
while (scanner.hasNextLine())
{
processLine((scanner.nextLine().split("\\s+"))[1], caches);
lineNum++;
}
printCaches(caches);
}
catch (FileNotFoundException e)
{
System.out.println("Fail: " + e);
}
}
}