/** * ArrayList extended to keep its contents in sorted order * @author gtowell * Created: March 2021 */ import java.util.ArrayList; import java.util.Scanner; public class SALextending> extends ArrayList implements SortedListInterface { /** * Required for serialization */ private static final long serialVersionUID = -7039052157199984372L; /** * Add an element to the sorted array list * @param stringToAdd * @return */ public boolean add(B stringToAdd) { int loc = findPlace(stringToAdd); insertAtLoc(stringToAdd, loc); return true; } /** * Find the place in the arraylist to put the string * @param toAdd the string to be added * @return the location in which to put the stirng */ private int findPlace(B toAdd) { int place=0; while (place=atLoc; ll--) { set(ll+1, get(ll)); } set(atLoc, toAdd); } /** * DO NOT LET THIS DO ANYTHING * @param toAdd * @param atLoc */ public void add(String toAdd, int atLoc) { System.err.println("Not Supported"); } /** * DO NOT LET THIS DO ANYTHING * @param i * @param v * @return */ public String set(int i, String v) { System.err.println("Not Supported"); String x = "123"; int a = x.charAt(0) - '0'; // == 1 return v; } public static void main(String[] args) { SALextending sal = new SALextending<>(); Scanner scann = new Scanner(System.in); System.out.print("Give me a String: "); String lin = scann.nextLine(); while (!lin.equals("0")) { sal.add(lin); System.out.print("Give me a String: "); lin = scann.nextLine(); } System.out.println(sal); scann.close(); } @Override public B remove(B b) { int loc = getPosition(b); if (loc<0) return null; B tmp = get(loc); remove(loc); return tmp; } @Override public int getPosition(B b) { int place=-1; while (place