Question
Complete the short program AlphaList.java. AlphaList.java implements an interfeace, AlphaListADT.java, and stores the objects in a collection that maintains an alphabetically sorted order. Some ADT
Complete the short program AlphaList.java. AlphaList.java implements an interfeace, AlphaListADT.java, and stores the objects in a collection that maintains an alphabetically sorted order. Some ADT JavaDocs explain in detail what each method should do. Complete the AlphaList implementation. It must correctly implement the AlphaListADT interface. Must USE LINEARNODES internally to store the data and must keep the helper strcuture, alphaCount up to date.
The following methods have been provided, use the JavaDoc comments to finish the methods:
- Constructor
- add(T element) method
- remove(T element) method
- toString()method
- some helper methods
-----------------------------------
package ADTs;
import Exceptions.*;
import java.util.ArrayList;
public interface AlphaListADT
CollectionADT
/**
* Adds the element, putting it in the correct order in the list,
* based on the AlphaKey for the generic object
* @param element element to be added
*/
public void add(T element) throws InvalidArgumentException;
/**
* Removes a particular element from the list
* @param element element to be removed
* @return element removed, null if not found
*/
public T remove(T element) throws EmptyCollectionException,
InvalidArgumentException;
/**
* Gets the number of objects in the list
* whose key begins with specified letter
* @param l char letter
* @return int number of objects in list beginning with l
* @pre l must be A-Z or a-z, other chars will throw exception
*/
public int alphaCount(char l) throws InvalidArgumentException;
/**
* Returns (but does not remove) an ArrayList of objects in the list
* whose key begins with the specified letter
* @param l char letter
* @return ArrayList of objects in list beginning with l
*/
public ArrayList
EmptyCollectionException, InvalidArgumentException;
/**
* Removes and return the first element in the list
* @return T first element in list, or null for empty list
*/
public T removeFirst() throws EmptyCollectionException,
InvalidArgumentException;
/**
* Removes and return the last element in the list
* @return T last element in list, or null for empty list
*/
public T removeLast() throws EmptyCollectionException,
InvalidArgumentException;
/**
* Removes and returns the first element in the list whose key begins
* with the specified char
* @param l char to use
* @return T first element that starts with char l, or null none * found or null for empty list
*/
public T removeFirstByLetter(char l) throws EmptyCollectionException,
InvalidArgumentException;
/**
* Removes and returns the last element in the list whose key begins
* with the specified char
* @param l char to use
* @return T last element that starts with char l, or null if
* none found or null for empty list
*/
public T removeLastByLetter(char l) throws EmptyCollectionException,
InvalidArgumentException;
}
package ADTs;
public interface AlphaKeyADT {
public String getKey();
}
package Exceptions;
public class InvalidArgumentException extends Exception {
public InvalidArgumentException(String arg) {
super("The argument " + arg + "was invalid.");
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started