Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question 1: Implement the following UML diagram (remember that shading + italics

ID: 3858018 • Letter: Q

Question

Question 1:

Implement the following UML diagram (remember that shading + italics here indicates an abstract class) Wordlist - list : ArrayList + WordList ): +getList O : ArrayList String +setList (ArrayListI) void //over-writes current ArrayList +abstract compare (w: WordList ): boolean AlphabeiedList + AlphabetizedList ( AlphabetizedList ( Array ListString> : I ) : // set internal ArrayList equal to parameter +compare ( +alphabetize () : void /I alphabetizes current ArrayList +merge (AlphabetizedList: al) : void +toString): String compare w : WordList ) : boolean // implement abstract method (w WordList): boolean implement abst

Explanation / Answer

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chegg.july;

import java.util.ArrayList;
import java.util.Collections;

/**
*
* @author Sam
*/
abstract class WordList {
    private ArrayList<String> list;

    public WordList() {
        list = new ArrayList<>();
    }

    public ArrayList<String> getList() {
        return (ArrayList<String>) list.clone();
    }

    public void setList(ArrayList<String> list) {
        this.list.clear();
        list.stream().forEach((s) -> {
            this.list.add(s);
        });
    }
  
    abstract boolean compare(WordList w);
}


/**
*
* @author Sam
*/
class AlphabetizedList extends WordList{

    public AlphabetizedList() {
        super();
    }
  
    public AlphabetizedList(ArrayList<String> list) {
        super();
        list.sort(null);
        setList(list);
    }

    @Override
    boolean compare(WordList w) {
        return getList().get(0).compareTo(w.getList().get(0)) < 0;
    }
  
    void alphadetize() {
        ArrayList<String> newList = getList();
        newList.sort(null);
        setList(newList);
    }
  
    void merge(AlphabetizedList other) {
            ArrayList<String> otherList = other.getList();
            ArrayList<String> thisList = getList();
            thisList.addAll(otherList);
            //thisList.sort(null); //not mentioned
            setList(thisList);
    }

    @Override
    public String toString() {
        return getList().toString();
    }
}  
  

class AlphaListDriver {
    public static void main(String[] args) {
        ArrayList<String> listA = new ArrayList<>();
        listA.add("Asia");
        listA.add("Africa");
        listA.add("Europe");
        listA.add("America");
        listA.add("Antarctica");
        ArrayList<String> listB = new ArrayList<>();
        listB.add("India");
        listB.add("France");
        listB.add("Nigeria");
        listB.add("Japan");
        listB.add("Australia");
        AlphabetizedList alA = new AlphabetizedList(listA);
        AlphabetizedList alB = new AlphabetizedList(listB);
        System.out.println("List A:" + alA);
        System.out.println("List B:" + alB);
      
        alA.merge(alB);
        System.out.println("List A:" + alA);
        alA.alphadetize();
        System.out.println("List A:" + alA);
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote