Skip to content

Commit 4394966

Browse files
authored
Updated README.md
1 parent 63a9c45 commit 4394966

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

README.md

+31-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ Java implementation of 6 CPU scheduling algorithms: *First Come First Serve (FCF
55
## Usage
66

77
Instantiate a `CPUScheduler` object of the algorithm
8+
89
```java
910
CPUScheduler fcfs = new FirstComeFirstServe();
1011
```
1112

1213
Add a new `Row` for every job queued
14+
1315
```java
1416
fcfs.add(new Row("P1", 0, 5));
1517
fcfs.add(new Row("P2", 2, 4));
@@ -18,19 +20,22 @@ fcfs.add(new Row("P4", 6, 6));
1820
```
1921

2022
Call the `process` method
23+
2124
```java
2225
fcfs.process();
2326
```
2427

2528
Use the accessors
29+
2630
```java
27-
fcfs.getAverageWaitingTime(); // 3.5
28-
fcfs.getAverageTurnAroundTime(); // 8.0
31+
fcfs.getAverageWaitingTime(); // 3.5
32+
fcfs.getAverageTurnAroundTime(); // 8.0
2933
```
3034

3135
### Round Robin
3236

3337
In the case of `RoundRobin`, you must first set a time quantum before calling `process`.
38+
3439
```java
3540
CPUScheduler rr = new RoundRobin();
3641

@@ -43,9 +48,32 @@ rr.setTimeQuantum(2);
4348
rr.process();
4449
```
4550

51+
### Rows
52+
53+
Using the object's `getRows` method will return a `List` of all queued `Row`. After `process`, each `Row` will reflect their respective computed *waiting time* and *turnaround time*.
54+
55+
```java
56+
CPUScheduler sjf = new ShortestJobFirst();
57+
List<Row> rows;
58+
59+
sjf.add(new Row("P1", 0, 5));
60+
sjf.add(new Row("P2", 2, 4));
61+
62+
rows = sjf.getRows();
63+
rows.get(1).getWaitingTime(); // 0
64+
rows.get(1).getTurnaroundTime(); // 0
65+
66+
sjf.process();
67+
68+
rows = sjf.getRows();
69+
rows.get(1).getWaitingTime(); // 3
70+
rows.get(1).getTurnaroundTime(); // 7
71+
```
72+
4673
### Timeline
4774

4875
Using the object's `getTimeline` method will return a `List` of `Event` which can be used to draw a Gantt chart. The timeline shows what job is being processed at the given time.
76+
4977
```java
5078
List<Event> timeline = fcfs.getTimeline();
5179

@@ -59,6 +87,7 @@ System.out.print(timeline.get(timeline.size() - 1).getFinishTime());
5987
```
6088

6189
Result:
90+
6291
```
6392
0
6493
| P1

0 commit comments

Comments
 (0)