Homework Solution: Programming Fundamentals III – Java Data Structures COSC 2436…

    Programming Fundamentals III – Java Data Structures COSC 2436 Lab #2 – Bag Implementations That Use Arrays Problem: Complete Programming Project 2, page 92. This will require that you use the ‘SetInterface’ of Chapter 1 instead of the ‘BagInterface’ of Chapter 2. You will add the methods of the interface to the existing class. Then, develop a test application that will verify the functionality of the solution. You may wish to look at the example test applications. As always, be sure to test ALL methods of the class and interface. Requirements: You will submit the lab following the normal lab procedures. Make sure to label your lab folder as follows: 2YourLastName To Be Done: - Open Resizable ArrayBag and rename as ArraySet.java - Global replace of ‘Bag’ with ‘Set’ - Re-write ‘add’ methods to prevent the addition of duplicate entries, using either the ‘contains’ method or ‘getIndexOf’ - We can remove ‘getFrequencyOf’ method. - Update the test class – replace the ‘testGetFrequencyOf’ method and add a method to verify that duplicates can’t be added *PDF of the texbook "Data Structures and Abstractions with Java 3rd edition" available upon request

    Expert Answer

     
    Solution: Since no implementation was provided by, hence a default c

    Programming Fundamentals III – Java Basis Structures COSC 2436

    Lab #2 – Bag Implementations That Authentication Arrays

    Problem:

    Thorough Programming Project 2, page 92.

    This procure insist-upon that you authentication the ‘SetInterface’ of Chapter 1 instead of the ‘BagInterface’ of Chapter 2. You procure subjoin the orders of the interface to the existing adjust. Then, enunciate a trial collision that procure demonstrate the functionality of the disentanglement. You may appetition to appear at the copy trial collisions.

    As frequently, be indisputable to trial ALL orders of the adjust and interface.

    Requirements: You procure refer the lab subjoined the natural lab procedures. Make indisputable to mark your lab folder as follows:

    2YourLastName

    To Be Done:

    – Open Resizable ArrayBag and rename as ArraySet.java

    – Global supply of ‘Bag’ with ‘Set’

    – Re-write ‘add’ orders to intercept the subjoinition of duplicate entries, using either the ‘contains’ order or ‘getIndexOf’

    – We can dislodge ‘getFrequencyOf’ order.

    – Update the trial adjust – supply the ‘testGetFrequencyOf’ order and subjoin a order to demonstrate that duplicates can’t be subjoined

    *PDF of the texbook “Basis Structures and Abstractions with Java 3rd edition” helpful upon request

    Expert Response

     

    Solution:

    Since no implementation was supposing by, hence a omission fabricate control ArraySet.java is charmed into inducement along with the changes instructed. (Assumptions were charmed accordingly) :

    Please perceive thorough implementation of the ‘ArraySet.java’ with the sense as comments:

    import java.util.ArrayList;
    import java.util.List;

    public adjust ArrayEstablished {

    /*
    * Since it is instructed to authentication ‘contains’ OR ‘getIndexOf’
    * so we are using java.util.List control implementing ‘Set’
    */
    private List<String> basisEstablished ;

    /*
    * Subjoin order implementation using
    * ‘contains’ order
    * if duplicate component detected then repay -1
    * else subjoin component and repay 0;
    */
    public int subjoin(String basis){
    if(this.dataEstablished == vain){
    dataEstablished = strangelightlight ArrayList<String>();
    }
    if(dataSet.contains(data)){
    repay -1;
    }else{
    dataSet.add(data);
    repay 0;
    }
    }

    /*
    * Trial order control subjoin()
    */
    public destitute trialAdd(String trialData){
    if( this.add(testData) == -1 ){
    System.out.println(“Duplicate component detected : ” + trialData);
    }
    }

    /*
    * Stereotypeing established
    */
    public destitute stereotype(){
    if(this.dataEstablished != vain){
    System.out.println(“Printing established components: “);
    dataSet.forEach(e -> System.out.print(e + ” “));
    }
    System.out.println(); // Stereotypeing a utter line
    }

    public static destitute deep(String[] args) {

    //Creating ArrayEstablished object
    ArrayEstablished established = strangelightlight ArraySet();
    set.add(“1”);
    set.add(“2”);
    set.add(“3”);
    set.add(“4”);
    set.add(“5”);
    set.add(“6”);

    set.print();

    System.out.println();

    //Running trial order
    set.testAdd(“2”);
    set.print();

    System.out.println()
    ;
    set.testAdd(“99”);
    set.print();
    }

    }

    Please perceive the screenshot of the quenchedput screen