Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class LLNode { private LLNode link; private T info; public LLNode(t info) { this.info = info; link = null; } public void setInfo(t info)

image text in transcribedimage text in transcribedimage text in transcribed

public class LLNode { private LLNode link; private T info; public LLNode(t info) { this.info = info; link = null; } public void setInfo(t info) // Sets info of this LLNode. { this.info = info; } public T getInfo() // Returns info of this LLNode. { return info; } public void setLink(LLNode link) // Sets link of this LLNode. { this. link = link; } public LLNode getLink // Returns link of this LLNode. { return link; } } Part 1 Copy all files from Files, List Exercise folder. Create a class called MyList which will hold Strings. The field in MyList is LLNode head; Create the following methods of MyList: default constructor: initialize head to null constructor with a String parm: create a list containing the parm .toString: return a String that contains all Strings in the list, separated by newlines void addAtFront(String newstr): add newstr to the front of the list boolean contains(String item): return true if item is in the list; return false if not Create a class to contain main; main should do the following: create a new MyList object that contains "blue"; for all of the following steps use the methods of the MyList class (printing the MyList will automatically call the toString method) add "green" to the front of your MyList add "red" to the front of your MyList print the MyList prompt for a word, add it to the front prompt for another word, add it to the front print the My List prompt for a String, check whether it's in the MyList; print messages for when the String is found and when it's not found print the MyList Part 2 Add the following methods to your MyList class: void addAfter(String before, String newstr): add newstr to the list after before; if before is not in the list, throw No SuchElementException String removeFront(): remove the first item in the list and return it; throw NoSuch ElementException if the list is empty Add the following to the end of your client code: add "purple" after "green" add "aqua" after "purple" print the MyList prompt for two Strings, add the first after the second; if the second is not in the list (catch the exception) print a message stating that first could not be added because second is not in the MyList print the MyList remove and then print each the first two items from the MyList print the MyList

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

More Books

Students also viewed these Databases questions

Question

What does "void" mean in programming?

Answered: 1 week ago