Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have a project in java but in jgrasp it fails several tests. I can\'t seem to

ID: 3739753 • Letter: I

Question

I have a project in java but in jgrasp it fails several tests. I can't seem to find the problems though.

It fails: TODOListTest.addOneItemLenOneTest Null Pointer Exception

TODOListTest.initListTest: The Array is null- list may not have been initialized. Actual: null

TODOListTest.clearItemsTest: Null Pointer Exception

TODOListTest.toDoListNameTest: The instance variable toDoList has not been declared. expected: <true> but was: <false>

TODOListTest.replacementAtTest: Null Pointer Exception

TODOListTest.addOneItemTest: Null Pointer Exception

TODOListTest.removeLastItemTest: Null Pointer Exception

I would work on these myself but I don't really understand the error messages and what they mean, thanks in advance.

Here is the code to work with:

1 /* This class encapsulates a list of user-defined items that should be done- a "TODO" list.

1 /This class encapsulates a list of user-defined items that should be done- a "TODO" list. 2Each item on the list is represented by a String object. 3The list is implemented by a String array. The array is initialized in the constructor to an 4initial length that is passed to the constructor. The initial array contains only NULL values 5A user adds an item (a String) to the list by calling the addItem method, passing in a String 6 that represents the to-do item 7Thus, the array may have fewer items (Strings) than its length. For example, assume the list has an initial length of 5. It looks like this: 10 NULL, NULL, NULL, NULL, NULL 12 Then, a user adds three items. It looks like this: 13"eat lunch"walk dog","study Java", NULL, NULL 14 15The length of the list is 5, the number of items is 3.The NULL values are unoccupied cells. 16 The capacity of the array is its length. The size of the data stored in the array is less than 17or equal to its capacity. 18 19If a user wants to add more items to a list that has no more NULL values, i.e. no more room, 20the expandArray method is called to double the length of the toDoList. The original Strings 21 are in the same positions, but the new array has double the capacity- more room for adding items. 22 */ 23 public class TODOList f 24 25 26 27 28 29 30Constructor that initializes the initialLength variable to the value passed in /YOUR Instance variable declarations here./ private String[] TODOList; private int initialLength; private int numItems;

Explanation / Answer

Hi , You got the error due to Object TODOListTest. You are not give a memory to this object so this is null and a null object can not call any function.

So you should create object with new keyword.

For creating object of given class You should

  TODOList tList = new TODOList(2);

Your code also have some error. I thing this is due to copy paste i correct them. Provide test class also by which error can clear more correctly.

CODE :