You will modify the add method in the LinkedBag class. The add method is the only thing
Question:
You will modify the add method in the LinkedBag class. The add method is the only thing you should modify in LinkedBag.
Add a second parameter to the method header that will be a boolean variable: public boolean add(T newEntry, boolean sorted)
The modification to the add method will make it possible to add new entries to the beginning of the list, as it does now, but also to add new entries in sorted order. The sorted parameter if set to false will result in the existing functionality being executed (it will add the new element to the beginning of the list), if set to true the new element will be inserted into the list such that the list is in sorted order.
So for example if these are the current entries in the list: 5 -> 8 -> 10 -> 16 -> 25
And the new entry that I want to put into the list is 14, it will put it into the list between 10 and 16: 5 -> 8 -> 10 -> 14 -> 16 -> 25
Remember, this is a generic class so it needs to be able to process any kind of object, just as it does now.
Task 2:
You will need to modify the add method header in the BagInterface class also to include the new parameter.
Task 3:
How to Create a test program to thoroughly test the add method. Name this file LinkedBagTester.java.
Part of this assignment is to create test cases that test all possible conditions of adding data into the list to verify that the new entry will get placed into the correct place in the list. In other words, does the new entry need to go at the beginning of the list, at the end, or some where in the middle? Also, you need to test the condition of adding elements not in sorted order so that you verify that your changes did not break the existing functionality.