Question: Write a java class LIST that outputs: List Empty List Empty List Empty Item not found Item not found Item not found Original list Do
Write a java class "LIST" that outputs:
List Empty List Empty List Empty Item not found Item not found Item not found Original list Do or do not. There is no try. Sorted Original List Do There do is no not. or try. Front is Do Rear is try. Count is 8 Is There present? true Is Dog present? false List with junk junk Do or moremorejunk do not. There is no try. morejunk Count is 11 List with junk removed Do or do not. There is no try. Count is 8 List Full List Full List Full List Full List Full List Full After filling List dummy dummy dummy dummy dummy dummy dummy Do or do not. There is no try. Count is 15 After removing dummy Do or do not. There is no try. Count is 8
//main:
public class AssignmentThree { public static void main(String[] args) { List myList = new List(15); // Cause List Empty Message myList.removeFront(); myList.removeRear(); myList.removeItem("a"); // Cause Not found message myList.addToFront("x"); myList.removeItem("y"); myList.removeItem("x"); myList.addAfterItem("x", "z"); myList.addBeforeItem("x", "z"); // Normal behavior myList.addToFront("not."); myList.addToFront("or"); myList.addToRear("is"); myList.addToRear("try."); myList.addAfterItem("is", "no"); myList.addBeforeItem("is", "There"); myList.addToFront("Do"); myList.addAfterItem("or", "do"); myList.print("Original list"); myList.printSorted("Sorted Original List"); sop(" Front is " + myList.getFront()); sop("Rear is " + myList.getRear()); sop("Count is " + myList.askCount()); sop("Is There present? " + myList.isPresent("There")); sop("Is Dog present? " + myList.isPresent("Dog")); myList.addToFront("junk"); myList.addToRear("morejunk"); myList.addAfterItem("or", "moremorejunk"); myList.print("List with junk"); sop("Count is " + myList.askCount()); myList.removeFront(); myList.removeRear(); myList.removeItem("moremorejunk"); myList.print("List with junk removed"); sop("Count is " + myList.askCount()); sop(""); // Cause List Full message for(int ii = 0; ii < 10; ++ii) { myList.addToFront(DUMMY); } myList.addToRear(DUMMY); myList.addBeforeItem("no", DUMMY); myList.addAfterItem("There", DUMMY); myList.print("After filling List"); sop("Count is " + myList.askCount()); while(myList.isPresent(DUMMY)) myList.removeItem(DUMMY); myList.print("After removing " + DUMMY ); sop("Count is " + myList.askCount()); } private static void sop(String s) { System.out.println(s); } private static final String DUMMY = "dummy"; }
//Class List:
public class List { public List(int size) { } public void addToFront(java.lang.String item) { } public void addToRear(java.lang.String item) { } public void addBeforeItem(java.lang.String beforeItem, java.lang.String item) { } public void addAfterItem(java.lang.String afterItem, java.lang.String item) { } public java.lang.String getFront() { } public java.lang.String getRear() { } public boolean isPresent(java.lang.String item) { } public int askCount() { } public void removeFront() { } public void removeRear() { } public void removeItem(java.lang.String item) { } public void print(java.lang.String title) { } public void printSorted(java.lang.String title) { } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
