Skip to content

Commit 3b6ed33

Browse files
committed
🔥 feat: refactor code for tabular data (#1)
1 parent 65b3c83 commit 3b6ed33

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

MemoryAllocation.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ class MemoryBlock {
66
boolean[] free = new boolean[] { false, true, false, true, false, true, false, true };
77
int[] processNumber = new int[] { 1, 2, 3, 4 };
88
int divs = memory.length;
9-
int processSize;
9+
int processSize;
1010
Scanner s = new Scanner(System.in);
1111

1212
void processInput() {
13-
System.out.println("Current Scenario of the Memory Allocation");
13+
System.out.println("\n\tCurrent Scenario of the Memory Allocation \n");
1414
printTable(-1);
1515
System.out.print("Enter the size of the process that needs to be added (in KB): ");
1616
processSize = s.nextInt();
17-
System.out.println("After First Fit \n");
17+
System.out.println("\n\t\tAfter First Fit \n");
1818
firstFit();
19-
System.out.println("After Best Fit \n");
19+
System.out.println("\n\t\tAfter Best Fit \n");
2020
bestFit();
21-
System.out.println("After Worst Fit \n");
21+
System.out.println("\n\t\tAfter Worst Fit \n");
2222
worstFit();
2323
}
2424

@@ -60,21 +60,24 @@ void worstFit() {
6060
}
6161

6262
void printTable(int pos) {
63-
System.out.print("No. \tMemory \tStatus \tProcess \n");
63+
System.out.print("+----------------------------------------------------------+\n");
64+
System.out.print("|\tNo.\tMemory \t\t Status \t Process |\n");
65+
System.out.print("+----------------------------------------------------------+\n");
6466
int j = 1, ok = 0;
6567
for (int i = 0; i < divs; i++) {
6668
if(i == pos) {
67-
System.out.print(i + 1 + " \t " + processSize + " \t " + "NF \t " + "Process " + (processNumber.length + 1) + "\n");
69+
System.out.print("|\t" + (i + 1) + " \t " + processSize + " \t\t " + " NF \t\t " + "Process " + (processNumber.length + 1) + " |");
6870
if(memory[i] - processSize != 0) {
69-
System.out.print(i + 2 + " \t " + (memory[i] - processSize) + " \t " + "F \t ");
71+
System.out.print("\n|\t" + (i + 2) + " \t " + (memory[i] - processSize) + " \t\t " + " F \t\t\t |");
7072
ok = 1;
7173
}
7274
}
7375
else {
74-
System.out.print((i + 1 + ok) + " \t " + memory[i] + " \t " + ((free[i]) ? "F" : "NF \t " + "Process " + j++));
76+
System.out.print("|\t" + (i + 1 + ok) + " \t " + memory[i] + " \t\t " + ((free[i]) ? "F \t\t\t |" : "NF \t\t " + "Process " + j++ + " |"));
7577
}
7678
System.out.println(' ');
7779
}
80+
System.out.print("+----------------------------------------------------------+\n");
7881
}
7982
}
8083

0 commit comments

Comments
 (0)