Question: In Java Please!! The starter project provides a basic implementation of the LList class, including the Node inner / private class. Your task is to

In Java Please!!
The starter project provides a basic implementation of the LList class, including the Node inner/private
class. Your task is to complete the following methods:
indexOf(int value): Returns the index of the first occurrence of the specified value in the list.
Note: The list uses 1-based indexing, so the first element is at index 1(not index 0). If the value is
not found, return -1.
reverse(): Reverses the order of elements in the list.
removeDuplicates(): Removes duplicate values from the list, leaving only unique elements in their
first-occurrence order.
Grading Rubric
public class GradingRubric {
public static void main(String[] args){
int score =0;
LList list = new LList();
list.add(1,10);
list.add(2,20);
list.add(3,30);
list.add(4,20);
list.add(5,40);
list.add(6,30);
System.out.print("Original List: ");
list.print_list();
// Test Case 1-3: Testing `indexOf`
System.out.println("
Test Cases for indexOf:");
score += runTestCase(list.indexOf(10)==1, "indexOf(10) should return 1");
score += runTestCase(list.indexOf(20)==2, "indexOf(20) should return 2(first occurrence)");
score += runTestCase(list.indexOf(50)==-1, "indexOf(50) should return -1(not found)");
// Test Case 4-6: Testing `add`
System.out.println("
Test Cases for add:");
list.add(50);
score += runTestCase(list.indexOf(50)==7, "add(50), indexOf(50) should return 7");
list.add(60);
score += runTestCase(list.indexOf(60)==8, "add(60), indexOf(60) should return 8");
list.add(20);
score += runTestCase(list.indexOf(20)==2, "indexOf(20) should still return 2(first occurrence)");
// Test Case 7-10: Testing `reverse`
System.out.println("
Test Cases for reverse:");
list.reverse();
score += runTestCase(list.indexOf(60)==2, "After reverse, indexOf(60) should return 2");
score += runTestCase(list.indexOf(10)==9, "After reverse, indexOf(10) should return 9");
list.reverse();
score += runTestCase(list.indexOf(10)==1, "After second reverse, indexOf(10) should return 0");
score += runTestCase(list.indexOf(60)==8, "After second reverse, indexOf(60) should return 7");
list.print_list();
System.out.println(list.getLength());
// Test Case 11-15: Testing `removeDuplicates`
System.out.println("
Test Cases for removeDuplicates:");
list.removeDuplicates();
score += runTestCase(list.indexOf(20)==2, "After removeDuplicates, indexOf(20) should return 1");
score += runTestCase(list.indexOf(30)==3, "After removeDuplicates, indexOf(30) should return 2");
score += runTestCase(list.indexOf(40)==4, "After removeDuplicates, indexOf(40) should return 3");
score += runTestCase(list.getLength()==6, "After removeDuplicates, size should be 6");
score += runTestCase(list.indexOf(60)==6, "After removeDuplicates, indexOf(60) should return 4");
// Test Case 16-17: Testing `isEmpty` and `clear`
System.out.println("
Test Cases for isEmpty and clear:");
score += runTestCase(!list.isEmpty(), "List should not be empty");
list.clear();
score += runTestCase(list.isEmpty(), "List should be empty after clear");
// Test Case 18-20: Testing `size` and adding elements after clear
System.out.println("
Test Cases for size and adding elements after clear:");
score += runTestCase(list.getLength()==0, "After clear, size should be 0");
list.add(100);
list.add(200);
score += runTestCase(list.getLength()==2, "After adding two elements, size should be 2");
list.add(100);
list.add(200);
score += runTestCase(list.getLength()==4, "After adding two elements, size should be 2");
// Final Score Display
System.out.println("
Total Score: "+ score +"/100");
}
// Utility method for running individual test cases
public static int runTestCase(boolean passed, String description){
if (passed){
System.out.println("Passed (5 points)-"+ description);
return 5;
} else {
System.out.println("Failed -"+ description);
return 0;
}
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!