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

Write a class definition for a CircularList class that implements the interface

ID: 3639325 • Letter: W

Question

Write a class definition for a CircularList class that implements the interface below. Note that the list methods involving indices should count from the first element of the list as index 0. Throw an exception if the index is out-of-bounds.

Then write a driver program to test your class.

The code must be completed how i asked to get full points. The code must include a comment for each method describing the method, a comment for each parameter describing what the parameter represents, and a comment for each variable declaration (including instance variables) describing what the variable represents.

Here is the code:

Explanation / Answer

public class js { public static void main(String args[]) { CircularLL circLL = new CircularLL(); if (args.length > 0) { if (args.length == 1) { int a = Integer.parseInt(args[0]); for (int i=0; i 1) { circLL.rotate(-1); circLL.head = circLL.head.next.next; circLL.size--; } System.out.println(circLL.toString() + " is the survivor."); } else if (args.length == 2) { if (args[0].compareTo("-a") == 0) { int n = Integer.parseInt(args[1]); for (int i=0; i 1) { circLL.rotate(-1); circLL.head = circLL.head.next.next; circLL.size--; System.out.println(circLL.toString()); } } else { int a = Integer.parseInt(args[0]); int b = Integer.parseInt(args[1]); while (a b) { for (int i=0; i 1) { circLL.rotate(-1); circLL.head = circLL.head.next.next; circLL.size--; } System.out.println(circLL.toString()); a--; } } else { // invalid arguments System.out.println("Invalid argument types. 1st and 3rd arguments should be -a and -s, respectively."); } } else { // invalid number of arguments System.out.println("Invalid number of arguments. Please run again with valid number of arguments."); } } else { // no arguments provided System.out.println("No arguments provided. Run again with arguments"); } } } public class Node 08 { 09 public Comparable data; 10 public Node next, prev; 11 Node(Comparable data){this.data = data;} 12 Node(Comparable data, Node next){this.data = data; this.next = next; this.prev = prev;} 13 public String toString(){return data.toString();} 14 } public interface List 10 { 11 public void clear(); // clear the list by removing each node 12 public int size(); // returns the number of nodes in the list 13 public void add(Comparable c); // add a node to the end of the circular list. End node is connected to head 14 public String toString(); 15 public boolean contains(Comparable c); // returns true if list contains c 16 public boolean isEmpty(); // returns true if list is empty 17 public Object remove(int index); // remove the node at index. List starts from index 0 18 public boolean remove(Comparable c); // remove the object c. return false if c is not in list 19 } ublic class CLLStringTester { 07 public static void main(String args[]) 08 { 09 CircularLL StringList = new CircularLL(); 10 StringList.add("guna"); 11 StringList.add("ananda"); 12 StringList.add("Mike"); 13 System.out.println(StringList); 14 System.out.println("The size of the list is " + StringList.size()); 15 String S = "guna"; 16 if (StringList.contains(S)) 17 System.out.println(S + " is here"); 18 else 19 System.out.println(S + " is not here"); 20 /* 21 StringList.remove(S); 22 System.out.println(StringList); 23 24 StringList.rotate(2); 25 System.out.println(StringList); 26 27 StringList.rotate(-1); 28 System.out.println(StringList); 29 */ 30 } 31 32 } public class CLLIntTester { 07 public static void main(String args[]) 08 { 09 CircularLL IntList = new CircularLL(); 10 IntList.add(new Integer(2)); 11 IntList.add(new Integer(4)); 12 IntList.add(new Integer(5)); 13 System.out.println(IntList); 14 System.out.println("The size of the list is " + IntList.size()); 15 Integer N = new Integer(4); 16 if (IntList.contains(N)) 17 System.out.println(N + " is here"); 18 else 19 System.out.println(N + " is not here"); 20 /* 21 IntList.remove(N); 22 System.out.println(IntList); 23 24 IntList.rotate(2); 25 System.out.println(IntList); 26 27 IntList.rotate(-1); 28 System.out.println(IntList); 29 */ 30 } 31 32 }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote