-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTable.java
65 lines (56 loc) · 2.59 KB
/
Table.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
public class Table {
private int numberOfProcess;
private int[][] inputTableMatrix;
private int[][] padSizeArray;
private int[][] padStartArray;
private int width = 16;
Table(int number, int[][] inputMatrix){
numberOfProcess = number;
inputTableMatrix = inputMatrix;
padSizeArray = new int[numberOfProcess][6];
padStartArray = new int[numberOfProcess][6];
}
private int countDigit(int num){
return String.valueOf(num).length();
}
private void findPadding(int numCol, int[][] inputTableMatrix){
for (int i = 0; i < numberOfProcess; i++) {
for (int j = 0; j < numCol; j++) {
padSizeArray[i][j] = width - countDigit(inputTableMatrix[i][j]);
padStartArray[i][j] = countDigit(inputTableMatrix[i][j]) + padSizeArray[i][j]/2;
}
}
}
public void inputTable() {
findPadding(4, inputTableMatrix);
String line = new String(new char[67]).replace('\0', '-'); //draw line
System.out.println("+" + line +"+");
System.out.println("| Process | Burst Time | Arrival Time | Priority |");
System.out.println("+" + line +"+");
for(int i = 0; i < numberOfProcess; i++){
String[] tempArray = new String[4];
for (int j = 0; j < 4; j++) {
String temp = String.format("%" + padStartArray[i][j] + "s", inputTableMatrix[i][j]);
tempArray[j] = String.format("%-" + width + "s", temp);
}
System.out.printf("|%s|%s|%s|%s|%n",tempArray[0],tempArray[1],tempArray[2],tempArray[3]);
}
System.out.println("+" + line +"+");
}
public void outputTable(int[][] outputTableMatrix) {
findPadding(6, outputTableMatrix);
String line = new String(new char[101]).replace('\0', '-'); //draw line
System.out.println("+" + line +"+");
System.out.println("| Process | Burst Time | Arrival Time | Priority |Turnaround Time| Waiting Time |");
System.out.println("+" + line +"+");
for(int i = 0; i < numberOfProcess; i++){
String[] tempArray = new String[6];
for (int j = 0; j < 6; j++) {
String temp = String.format("%" + padStartArray[i][j] + "s", outputTableMatrix[i][j]);
tempArray[j] = String.format("%-" + width + "s", temp);
}
System.out.printf("|%s|%s|%s|%s|%s|%s|%n",tempArray[0],tempArray[1],tempArray[2],tempArray[3],tempArray[4],tempArray[5]);
}
System.out.println("+" + line +"+");
}
}