Hello everyone. I have a bankers algorithm written in java that gets inputs from
ID: 3747597 • Letter: H
Question
Hello everyone. I have a bankers algorithm written in java that gets inputs from a .txt file. The file has 7 processes and 5 resources however, when the program runs, it doesn't sum the resource columns correctly. The program runs correctly for smaller matricies (4 processes, 3 resources), not sure what the issue is and have been looking over the code for awhile so maybe another set of eyes would help...thanks
BankersAlgorithm.java
bankers.txt
OUTPUT
"C:Program FilesJavajdk-9.0.4injava.exe" "-javaagent:C:Program FilesJetBrainsIntelliJ IDEA Community Edition 2018.1.3libidea_rt.jar=64246:C:Program FilesJetBrainsIntelliJ IDEA Community Edition 2018.1.3in" -Dfile.encoding=UTF-8 -classpath C:UsersndreOneDriveDocumentsCMSC412outproductionCMSC412 BankersAlgorithm
java.lang.NullPointerException
at java.base/java.util.StringTokenizer.<init>(StringTokenizer.java:199)
at java.base/java.util.StringTokenizer.<init>(StringTokenizer.java:236)
at BankersAlgorithm.main(BankersAlgorithm.java:202)
Number of Processes : 7
Number of Resources : 5
claimMatrix :
1 1 2 3 5
3 2 4 4 6
2 2 2 2 2
0 0 0 0 5
1 3 6 7 6
2 2 2 0 0
1 0 0 0 1
Allocation Matrix :
0 1 2 3 4
2 0 3 4 6
1 2 0 0 0
0 0 0 0 4
1 3 4 7 5
2 1 2 0 0
0 0 0 0 1
Resource Vector :
0 0 0 0 0
Need Matrix :
1 0 0 0 1
1 2 1 0 0
1 0 2 2 2
0 0 0 0 1
0 0 2 0 1
0 1 0 0 0
1 0 0 0 0
Initial Available Vector :
-6 -7 -11 -14 -20
This system is not in a safe state!!!
Process finished with exit code 0
Explanation / Answer
Hi, I go through the code you have written and It looks like working code. There is no problem in the code but as per the provided input file data bankers.txt, resource vector is missing in the above input. just add one more line to the input (resource vector)
I verified , I got the out put as well.
Correct input in bankers.txt
7
5
1 1 2 3 5
3 2 4 4 6
2 2 2 2 2
0 0 0 0 5
1 3 6 7 6
2 2 2 0 0
1 0 0 0 1
0 1 2 3 4
2 0 3 4 6
1 2 0 0 0
0 0 0 0 4
1 3 4 7 5
2 1 2 0 0
0 0 0 0 1
9 9 20 20 20
OutPut:
Number of Processes : 7
Number of Resources : 5
claimMatrix :
1 1 2 3 5
3 2 4 4 6
2 2 2 2 2
0 0 0 0 5
1 3 6 7 6
2 2 2 0 0
1 0 0 0 1
Allocation Matrix :
0 1 2 3 4
2 0 3 4 6
1 2 0 0 0
0 0 0 0 4
1 3 4 7 5
2 1 2 0 0
0 0 0 0 1
Resource Vector :
9 9 20 20 20
Need Matrix :
1 0 0 0 1
1 2 1 0 0
1 0 2 2 2
0 0 0 0 1
0 0 2 0 1
0 1 0 0 0
1 0 0 0 0
Initial Available Vector :
3 2 9 6 0
Process Sequence : 2 1 3 4 5 6 7
This system is in a safe state!!!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.