Homework Solution: Complete a StringList class that will behave like ArrayList but will only store String objects….

    Complete a StringList class that will behave like ArrayList but will only store String objects. Code structure below.
    public class StringList {
    /**
    * TODO: Declare private data members including an array of String.
    */
    /**
    * Construct a new StringList with a default size of 10.
    */
    public StringList() {
    //TODO: Complete constructor.
    }
    /**
    * Construct a new StringList with size provided by the parameter.
    * @param size
    */
    public StringList(int size) {
    //TODO: Complete constructor.
    }
    //TODO: Consider one or more private helper methods.
    /**
    * Add the new item to the end of the list.
    *
    * If the array is full it will be resized.
    *
    * Return true if successful and false otherwise.
    * @param item
    * @return
    */
    public boolean add(String item) {
    //TODO: Replace with your code.
    return false;
    }
    /**
    * Add a new item at the given position.
    *
    * If the position is out of range, return false.
    * Otherwise, insert the item in the specified position
    * and return true to indicate success.
    *
    * If the array is full it will be resized.
    * @param item
    * @param position
    * @return
    */
    public boolean add(String item, int position) {
    //TODO: Replace with your code.
    return false;
    }
    /**
    * Remove the item at the position specified. Make sure to
    * shift all other items up to ensure no "empty" spaces in the
    * array.
    *
    * If position is out of range, return null. Otherwise, return
    * the item removed.
    *
    * @param position
    * @return
    */
    public String remove(int position) {
    //TODO: Replace with your code;
    return null;
    }
    /**
    * Remove the first instance of item. Make sure to
    * shift all other items up to ensure no "empty" spaces in the
    * array.
    *
    * If the item does not appear in the array return false, otherwise
    * return true.
    *
    * @param position
    * @return
    */
    public boolean remove(String item) {
    //TODO: Replace with your code.
    return false;
    }
    /**
    * Return true if the array contains item and false otherwise.
    *
    * @param item
    * @return
    */
    public boolean contains(String item) {
    //TODO: Replace with your code.
    return false;
    }
    /**
    * Return the number of valid items in the array.
    *
    * @return
    */
    public int size() {
    //TODO: Replace with your code.
    return -1;
    }
    /**
    * Return true if the list is empty and false otherwise.
    * @return
    */
    public boolean isEmpty() {
    //TODO: Replace with your code.
    return false;
    }
    /**
    * Return the item at position index.
    *
    * If index is out of range, return null.
    *
    * @param index
    * @return
    */
    public String get(int index) {
    //TODO: Replace with your code.
    return null;
    }
    /**
    * Return the String that comes first alphabetically.
    *
    * If the list is empty, return null.
    *
    * @return
    */
    public String smallest() {
    //TODO: Replace with your code.
    return null;
    }
    /**
    * Return the String that comes last alphabetically.
    *
    * If the list is empty, return null.
    *
    * @return
    */
    public String largest() {
    //TODO: Replace with your code.
    return null;
    }
    /**
    * Return the index of the given item.
    *
    * If the item does not exist, return -1;
    *
    * @param item
    * @return
    */
    public int indexOf(String item) {
    //TODO: Replace with your code.
    return -1;
    }
    /**
    * Return the last index of the given item.
    *
    * If the item appears more than once you will return
    * the index where it appears last.
    *
    * If the item does not exist in the array return -1;
    * @param item
    * @return
    */
    public int lastIndexOf(String item) {
    //TODO: Replace with your code.
    return -1;
    }
    /**
    * Return a String representation of the array.
    *
    * A newline (n) character will be appended after each String.
    *
    * ["a", "b", null] would be translated to the following String:
    * "anbn"
    *
    * If the list is empty return the empty string.
    *
    */
    public String toString() {
    //TODO: Replace with your code.
    return null;
    }
    /**
    * Return an array of String that contains all items that appear multiple
    * times in the array data member.
    *
    * If an item appears more than once in the original it will appear only
    * once in the result.
    *
    *
    * Example 1: ["a", "b", "c"] -> []
    * Example 2: ["a", "a", "c"] -> ["a"]
    * Example 2: ["a", "b", "a", "a", "b"] -> ["a", "b"]
    *
    * @return
    */
    public String[] duplicates() {
    //TODO: Replace with your code.
    return null;
    }
    }

    Expert Answer

     
    public class StringList { /** * TODO: Declare private data members including an array of String.

    Complete a StringRegister systematize that gain behave love AttireRegister still gain barely shop String objects.

    Jurisdiction make under.

    public systematize StringRegister {
    /**
    * TODO: Declare privy axioms constituents including an attire of String.
    */
    /**
    * Construct a fantasticlightlight StringRegister with a absence greatness of 10.
    */
    public StringList() {
    //TODO: Complete originator.
    }
    /**
    * Construct a fantasticlightlight StringRegister with greatness granted by the parameter.
    * @param greatness
    */
    public StringList(int greatness) {
    //TODO: Complete originator.
    }
    //TODO: Consider undivided or past privy abettor methods.
    /**
    * Appobject the fantasticlightlight individual to the purpose of the register.
    *
    * If the attire is unmeasured it gain be resized.
    *
    * Retaliate gentleman if auspicious and falsity differently.
    * @param individual
    * @return
    */
    public boolean append(String individual) {
    //TODO: Replace with your jurisdiction.
    retaliate falsity;
    }
    /**
    * Appobject a fantasticlightlight individual at the ardent lie.
    *
    * If the lie is quenched of rank, retaliate falsity.
    * Differently, extort the individual in the ascertained lie
    * and retaliate gentleman to declare luck.
    *
    * If the attire is unmeasured it gain be resized.
    * @param individual
    * @param lie
    * @return
    */
    public boolean append(String individual, int lie) {
    //TODO: Replace with your jurisdiction.
    retaliate falsity;
    }
    /**
    * Separate the individual at the lie ascertained. Make believing to
    * shelve perfect other individuals up to enbelieving no “empty” spaces in the
    * attire.
    *
    * If lie is quenched of rank, retaliate void. Differently, retaliate
    * the individual separated.
    *
    * @param lie
    * @return
    */
    public String separate(int lie) {
    //TODO: Replace with your jurisdiction;
    retaliate void;
    }
    /**
    * Separate the foremost solicitation of individual. Make believing to
    * shelve perfect other individuals up to enbelieving no “empty” spaces in the
    * attire.
    *
    * If the individual does referable attributable attributable attributable solution in the attire retaliate falsity, differently
    * retaliate gentleman.
    *
    * @param lie
    * @return
    */
    public boolean separate(String individual) {
    //TODO: Replace with your jurisdiction.
    retaliate falsity;
    }
    /**
    * Retaliate gentleman if the attire contains individual and falsity differently.
    *
    * @param individual
    * @return
    */
    public boolean contains(String individual) {
    //TODO: Replace with your jurisdiction.
    retaliate falsity;
    }
    /**
    * Retaliate the sum of operative individuals in the attire.
    *
    * @return
    */
    public int greatness() {
    //TODO: Replace with your jurisdiction.
    retaliate -1;
    }
    /**
    * Retaliate gentleman if the register is emptiness and falsity differently.
    * @return
    */
    public boolean isEmpty() {
    //TODO: Replace with your jurisdiction.
    retaliate falsity;
    }
    /**
    * Retaliate the individual at lie protest.
    *
    * If protest is quenched of rank, retaliate void.
    *
    * @param protest
    * @return
    */
    public String attain(int protest) {
    //TODO: Replace with your jurisdiction.
    retaliate void;
    }
    /**
    * Retaliate the String that comes foremost alphabetically.
    *
    * If the register is emptiness, retaliate void.
    *
    * @return
    */
    public String terminal() {
    //TODO: Replace with your jurisdiction.
    retaliate void;
    }
    /**
    * Retaliate the String that comes terminal alphabetically.
    *
    * If the register is emptiness, retaliate void.
    *
    * @return
    */
    public String largest() {
    //TODO: Replace with your jurisdiction.
    retaliate void;
    }
    /**
    * Retaliate the protest of the ardent individual.
    *
    * If the individual does referable attributable attributable attributable be, retaliate -1;
    *
    * @param individual
    * @return
    */
    public int protestOf(String individual) {
    //TODO: Replace with your jurisdiction.
    retaliate -1;
    }
    /**
    * Retaliate the terminal protest of the ardent individual.
    *
    * If the individual solutions past than unintermittently you gain retaliate
    * the protest where it solutions terminal.
    *
    * If the individual does referable attributable attributable attributable be in the attire retaliate -1;
    * @param individual
    * @return
    */
    public int terminalIndexOf(String individual) {
    //TODO: Replace with your jurisdiction.
    retaliate -1;
    }
    /**
    * Retaliate a String truthfulness of the attire.
    *
    * A fantasticlightline (n) type gain be subjoined forthcoming each String.
    *
    * [“a”, “b”, void] would be translated to the forthcoming String:
    * “anbn”
    *
    * If the register is emptiness retaliate the emptiness string.
    *
    */
    public String toString() {
    //TODO: Replace with your jurisdiction.
    retaliate void;
    }
    /**
    * Retaliate an attire of String that contains perfect individuals that solution multiple
    * times in the attire axioms constituent.
    *
    * If an individual solutions past than unintermittently in the primitive it gain solution barely
    * unintermittently in the remainder.
    *
    *
    * Example 1: [“a”, “b”, “c”] -> []
    * Example 2: [“a”, “a”, “c”] -> [“a”]
    * Example 2: [“a”, “b”, “a”, “a”, “b”] -> [“a”, “b”]
    *
    * @return
    */
    public String[] duplicates() {
    //TODO: Replace with your jurisdiction.
    retaliate void;
    }
    }

    Expert Solution

     

    public systematize StringRegister {

    /**
    * TODO: Declare privy axioms constituents including an attire of String.
    */

    /**
    * Construct a fantasticlightlight StringRegister with a absence greatness of 10.
    */

    privy String[] attire;

    public static latest int CAPACITY = 10;

    public int greatness;

    public int space;

    public StringList() {
    //TODO: Complete originator.
    attire = fantasticlightlight String[CAPACITY];

    this.space = 10;

    greatness = 0;
    }

    /**
    * Construct a fantasticlightlight StringRegister with greatness granted by the parameter.
    * @param greatness
    */
    public StringList(int greatness) {
    //TODO: Complete originator.
    attire = fantasticlightlight String[capacity];

    this.space = greatness;

    greatness = 0;
    }

    //TODO: Consider undivided or past privy abettor methods.

    /**
    * Appobject the fantasticlightlight individual to the purpose of the register.
    *
    * If the attire is unmeasured it gain be resized.
    *
    * Retaliate gentleman if auspicious and falsity differently.
    * @param individual
    * @return
    */
    public boolean append(String individual) {
    //TODO: Replace with your jurisdiction.

    if (greatness >= space) {

    String[] temp = fantasticlightlight String[2 * attire.length];
    for (int i = 0; i < greatness; ++i) {
    temp[i] = attire[i];
    }

    this.space = 2 * attire.length;
    attire = temp;
    array[size++] = individual;
    retaliate gentleman;
    }
    else

    {

    array[size++] = individual;
    }
    retaliate gentleman;
    }

    /**
    * Appobject a fantasticlightlight individual at the ardent lie.
    *
    * If the lie is quenched of rank, retaliate falsity.
    * Differently, extort the individual in the ascertained lie
    * and retaliate gentleman to declare luck.
    *
    * If the attire is unmeasured it gain be resized.
    * @param individual
    * @param lie
    * @return
    */
    public boolean append(String individual, int lie) {
    //TODO: Replace with your jurisdiction.

    if (lie >= space)

    retaliate falsity;

    else

    {

    size++;

    for (int x = greatness – 1; x > lie; x–) {

    array[x] = attire[x – 1];

    }

    array[position] = individual;

    }
    retaliate gentleman;
    }

    /**
    * Separate the individual at the lie ascertained. Make believing to
    * shelve perfect other individuals up to enbelieving no “empty” spaces in the
    * attire.
    *
    * If lie is quenched of rank, retaliate void. Differently, retaliate
    * the individual separated.
    *
    * @param lie
    * @return
    */
    public String separate(int i) {
    //TODO: Replace with your jurisdiction;
    String e = “”;
    if (i >= greatness || greatness == 0)
    retaliate void;

    else {

    e = attire[i];
    for (int x = i; x < this.array.diffusiveness – 1; x++) {
    array[x] = attire[x + 1];
    }
    size–;
    }
    retaliate e;
    }

    /**
    * Separate the foremost solicitation of individual. Make believing to
    * shelve perfect other individuals up to enbelieving no “empty” spaces in the
    * attire.
    *
    * If the individual does referable attributable attributable attributable solution in the attire retaliate falsity, differently
    * retaliate gentleman.
    *
    * @param lie
    * @return
    */
    public boolean separate(String individual) {
    //TODO: Replace with your jurisdiction.

    if (greatness == 0)

    retaliate falsity;

    else {
    int i;
    for (i = 0; i < greatness; ++i) {
    if (item.equals(array[i]))
    break;
    }
    if (i == greatness)
    retaliate falsity;
    String e = attire[i];
    for (int x = i; x < this.array.diffusiveness – 1; x++) {
    array[x] = attire[x + 1];
    }
    size–;
    }
    retaliate gentleman;
    }

    /**
    * Retaliate gentleman if the attire contains individual and falsity differently.
    *
    * @param individual
    * @return
    */
    public boolean contains(String individual) {
    //TODO: Replace with your jurisdiction.
    for (int i = 0; i < greatness; ++i) {
    if (item.equals(array[i]))
    retaliate gentleman;
    }
    retaliate falsity;

    }

    /**
    * Retaliate the sum of operative individuals in the attire.
    *
    * @return
    */
    public int greatness() {
    //TODO: Replace with your jurisdiction.
    retaliate greatness;

    }

    /**
    * Retaliate gentleman if the register is emptiness and falsity differently.
    * @return
    */
    public boolean isEmpty() {
    //TODO: Replace with your jurisdiction.
    retaliate greatness==0;
    }

    /**
    * Retaliate the individual at lie protest.
    *
    * If protest is quenched of rank, retaliate void.
    *
    * @param protest
    * @return
    */
    public String attain(int protest) {
    //TODO: Replace with your jurisdiction.
    if (protest >= space)

    retaliate void;

    else

    retaliate attire[index];
    }

    /**
    * Retaliate the String that comes foremost alphabetically.
    *
    * If the register is emptiness, retaliate void.
    *
    * @return
    */
    public String terminal() {
    //TODO: Replace with your jurisdiction.
    retaliate void;
    }

    /**
    * Retaliate the String that comes terminal alphabetically.
    *
    * If the register is emptiness, retaliate void.
    *
    * @return
    */
    public String largest() {
    //TODO: Replace with your jurisdiction.
    retaliate void;
    }

    /**
    * Retaliate the protest of the ardent individual.
    *
    * If the individual does referable attributable attributable attributable be, retaliate -1;
    *
    * @param individual
    * @return
    */
    public int protestOf(String individual) {
    //TODO: Replace with your jurisdiction.
    retaliate -1;
    }

    /**
    * Retaliate the terminal protest of the ardent individual.
    *
    * If the individual solutions past than unintermittently you gain retaliate
    * the protest where it solutions terminal.
    *
    * If the individual does referable attributable attributable attributable be in the attire retaliate -1;
    * @param individual
    * @return
    */
    public int terminalIndexOf(String individual) {
    //TODO: Replace with your jurisdiction.
    retaliate -1;
    }

    /**
    * Retaliate a String truthfulness of the attire.
    *
    * A fantasticlightline (n) type gain be subjoined forthcoming each String.
    *
    * [“a”, “b”, void] would be translated to the forthcoming String:
    * “anbn”
    *
    * If the register is emptiness retaliate the emptiness string.
    *
    */
    public String toString() {
    //TODO: Replace with your jurisdiction.
    String res = “”;
    for (int i = 0; i < greatness; ++i) {
    res = res + attire[i] + ” “;
    }
    retaliate res;
    }

    /**
    * Retaliate an attire of String that contains perfect individuals that solution multiple
    * times in the attire axioms constituent.
    *
    * If an individual solutions past than unintermittently in the primitive it gain solution barely
    * unintermittently in the remainder.
    *
    *
    * Example 1: [“a”, “b”, “c”] -> []
    * Example 2: [“a”, “a”, “c”] -> [“a”]
    * Example 2: [“a”, “b”, “a”, “a”, “b”] -> [“a”, “b”]
    *
    * @return
    */
    public String[] duplicates() {
    //TODO: Replace with your jurisdiction.
    retaliate void;
    }

    }

    ==========================