Question: INSTRUCTIONS: USING JAVA your task here is to create an AlwaysSortedLinkedList class that has the following properties: it will be generic...so you can toss whatever
INSTRUCTIONS: USING JAVA
your task here is to create an AlwaysSortedLinkedList class that has the following properties:
- it will be generic...so you can toss whatever reference type you want in it...as long as that class implements Comparable!
- any time an element is added to this list, the list must be in order based on the natural ordering of its elements.
- it will implement the SimpleList interface that's included in the starting project.
- it will also implement the Iterable
interface; this means you can for-each through your AlwaysSortedLinkedList objects! Cool. - you should make your Iterator class a non-static member class (so it's declared private Iterator
and inside your AlwaysSortedLinkedList class). It needs to be non-static because it needs to access instance variables of its enclosing class. Of course, I realize I can't force you to do so. But still...practice good practice, folks! - WHAT TO DO ???
- Create a AlwaysSortedLinkedList
class in the main package. This class represents a list that you can add things to and its behaviour is described in the Preamble: - if all the AlwaysSortedList tests pass, consider that puppy done!
- Complete the App.java run method so that when you run Main.java, the program behaves as expected by the MainTests.
- I've added a useful method in App.java that removes some of the drudgery.
- RUNNING EXAMPLE :
-
Here is an example run of a working solution (user input in bold):
Enter a list of words separated by spaces. If the word has a + in front of it, I'll add it. If the word has a - in front of it, I'll remove it. Otherwise, I'll ignore it. I'll stop when you enter a # for the word. Let's begin!
Your words> -egad! +zoinks! +gadzooks! +wowzers! +egad! +zoinks! #
Here are the words, in order: egad! gadzooks! wowzers! zoinks! zoinks!
-
package main; public class App { public void run() { // TODO: code this run so that it works as shown in the example // output in the instructions - and so that all the tests in MainTests pass as well } private void displayDemInstructions() { System.out.println("Enter a list of words separated by spaces."); System.out.println("If the word has a + in front of it, I'll add it."); System.out.println("If the word has a - in front of it, I'll remove it."); System.out.println("Otherwise, I'll ignore it."); System.out.println("I'll stop when you enter a # for the word."); System.out.println("Let's begin!"); System.out.println(); } } -
package main; public interface SimpleList > extends Iterable { /** * Adds the specified element to this List. The element will be added such that the elements in * this List retain their natural ordering. * * @param e the element to be added */ void add(E e); /** * Removes the first occurrence of the specified element from this List. If the element does not * exist, that's cool - the list doesn't change and no exceptions are thrown, but null is * returned. * * @param e the element to be removed from this list * @return the element that was removed, or null if it wasn't found in this List */ E remove(E e); /** * Returns the element found at the given index in this List. * * @param index the index where you want to grab an element * @return the element at the given index * @throws IndexOutOfBoundsException if the index is out of range */ E get(int index); /** * Returns the index of the first element in the list that equals the given target. If no such * element is found, returns -1. * * @param target the element to search for in the list * @return the index of the target, or -1 if its not in the list */ int indexOf(E target); /** * Returns the number of elements in this List. * * @return the number of elements in this List */ int size(); /** * Returns true if there are no elements in this List. * * @return true if this list has not elements */ boolean isEmpty(); }
package main; public class Main { public static void main(String[] args) { App app = new App(); app.run(); } } Please I have a time limit for this question and I need help with it as quickly as possible. Also, please, ensure to include writing the following methods in the code to pass all tests: add(), remove(), get(). Thanks so much in advance
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
