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

JAVA GENERIC DOUBLY LINKED LIST WITH LIST INTERFACE Hello, I need some serious h

ID: 3835861 • Letter: J

Question

JAVA GENERIC DOUBLY LINKED LIST WITH LIST INTERFACE Hello, I need some serious help on creating a generic doubly linked list which implements a list interface with methods listed below. It seems really easy, but I'm burning my brain out trying to figure it out. I'd appreciate all the help I can get!

public interface ListInterface<T> {
   boolean isEmpty();
       // Sees whether this list is empty.
       // return True if the list is empty, or false if not.
   boolean add(T newEntry);
       // Adds a new entry to the list.
       // post If successful, newEntry is stored in the list and
       // the count of items in the list has increased by 1.
       // param newEntry The object to be added as a new entry.
       // return True if addition was successful, or false if not.
   boolean remove(T anEntry);
       // Removes one occurrence of a given entry from this list, if possible.
       // post If successful, anEntry has been removed from the list and the count of
       // items in the list has decreased by 1.
       // param anEntry The entry to be removed.
       // return True if removal was successful, or false if not.
   void clear();
       // Removes all entries from this list.
       // post List contains no items, and the count of items is 0.
   int getFrequencyOf(T anEntry);
       // Counts the number of times a given entry appears in list.
       // param anEntry The entry to be counted.
       // return The number of times anEntry appears in the list.
   boolean contains(T anEntry);
       // Tests whether this list contains a given entry.
       // param anEntry The entry to locate.
       // return True if list contains anEntry, or false otherwise.
  
}

Explanation / Answer

Find the below class as the interface which is your above problem statement and also the Driver Class which implements the unimplemented methods.

***********

ListInterface.java

package com.sagar.oracle;

//The interface constructed is the generic interface

public interface ListInterface<T>{
   boolean isEmpty();
   // Sees whether this list is empty.
   // return True if the list is empty, or false if not.
   boolean add(T newEntry);
   // Adds a new entry to the list.
   // post If successful, newEntry is stored in the list and
   // the count of items in the list has increased by 1.
   // param newEntry The object to be added as a new entry.
   // return True if addition was successful, or false if not.
   boolean remove(T anEntry);
   // Removes one occurrence of a given entry from this list, if possible.
   // post If successful, anEntry has been removed from the list and the count of
   // items in the list has decreased by 1.
   // param anEntry The entry to be removed.
   // return True if removal was successful, or false if not.
   void clear();
   // Removes all entries from this list.
   // post List contains no items, and the count of items is 0.
   int getFrequencyOf(T anEntry);
   // Counts the number of times a given entry appears in list.
   // param anEntry The entry to be counted.
   // return The number of times anEntry appears in the list.
   boolean contains(T anEntry);
   // Tests whether this list contains a given entry.
   // param anEntry The entry to locate.
   // return True if list contains anEntry, or false otherwise.


}

******************

Driver Class which implements the interface with the unimplemented methods

Driver.java

package com.sagar.oracle;

import java.util.ArrayList;

public class Driver<T> implements ListInterface<T> {


   ArrayList<T> list;

   int count;
   @Override
   public boolean isEmpty() {
       // TODO Auto-generated method stub

       if(list.isEmpty()){
           return true;
       }
       else
           return false;
   }

   @Override
   public boolean add(T newEntry) {
       // TODO Auto-generated method stub

       list.add(newEntry);
       if(list.contains("isSuccessful")){
           list.add(newEntry);
           count+=1;
           return true;
       }
       else
           return false;
   }

   @Override
   public boolean remove(T anEntry) {
       // TODO Auto-generated method stub
       list.remove(anEntry);
       if(list.contains("isSuccessful")){
           list.remove(anEntry);
           count-=1;
           return true;
       }
       else
           return false;
   }

   @Override
   public void clear() {
       // TODO Auto-generated method stub

       list.clear();
       System.out.println("Removed all the entries from the list");
       count =0;

   }

   @Override
   public int getFrequencyOf(T anEntry) {
       // TODO Auto-generated method stub
       count= list.size();
       if(count!=0){
           list.add(anEntry);

       }
       return count;
   }

   @Override
   public boolean contains(T anEntry) {
       // TODO Auto-generated method stub

       if(list.contains(anEntry)){
           System.out.println("List Contains is Successfull");
           return true;
       }
       else
           return false;
   }

}

**************************************

P.S KINDLY OBSERVE THE METHOS IMPLEMENTATION IN THE DRIVER CLASS AND THOSE ARE SELF EXPLAINATORY