In this assignment, you will expand on Lab 4/ 5’s implementation of BlockChain in two ways: moving it to using the Java Linked List class, and making a collection of BlockChains in an ArrayList.
Note – you may use my posted solution for Lab 5 to begin if you find that helpful. I suggest that you implement the changes in the order that I have listed below – so get (a) changes working….then add (b).
a) The BlockChain class will be revised to use the LinkedList java class (instead of keeping head/tail and doing all the linked list programming ourselves, we will use the LinkedList methods). So – the data members in BlockChain class will now be:
private LinkedList <Block blockChain;
private String courseName;
The methods will need to be rewritten.
Note – this will mean a change to the Block class in that you will need to remove the nextOne field in that class and update the methods appropriately. The currentHash and previousHash fields in this class still must be handled by us in our code. (The LinkedList class in Java now looks after only the link to the next Block).
b) Add a College class to this project whose data members will be
private ArrayList<BlockChain college;
private String collegeName;
Note that each BlockChain is actually representing the grades in a course. (so we could have changed the BlockChain class name to CourseGrades).
The menu for the main method will have the following options:
- Display the courses (and their corresponding data) – for each of the BlockChains (courses) in the college ArrayList
- Add a new course
- Add a new block (then user will be prompted which course to add the block to)
- Add a bad block (artificial – but we will keep this so we can have bad blocks)
- Verify college – verify each of the BlockChains in the college ArrayList
Note – in my sample output below, I did not test all error conditions – but you must do this in your program (and then write a test plan for only the changes made in this program).
Sample Output: (green is user input)
Enter 1 to display the college courses:
2 to add a new course:
3 to add a block:
4 to verify chains:
5 to fix a chain:
6 to quit:
1
For college: Algonquin
Enter 1 to display the college courses:
2 to add a new course:
3 to add a block:
4 to verify chains:
5 to fix a chain:
6 to quit:
2
Enter name of course to add:
CST8130
Enter 1 to display the college courses:
2 to add a new course:
3 to add a block:
4 to verify chains:
5 to fix a chain:
6 to quit:
1
For college: Algonquin
For course: CST8130
[
0 100 2152018 current: 24455.0 previous: 0.0]
Enter 1 to display the college courses:
2 to add a new course:
3 to add a block:
4 to verify chains:
5 to fix a chain:
6 to quit:
3
Enter which course to add :
0 CST8130:
0
Add good block or bad? (g for good, anything else for bad):