SlideShare a Scribd company logo
package ADTs;
public interface CollectionADT<T> {
public boolean isEmpty();
public int size();
@Override
public String toString();
}
**********************************************************
package ADTs;
import Exceptions.*;
/**
* An interface for an ordered (NOT SORTED) List
* Elements stay in the order they are put in to the list
* For use in Data Structures & Algorithms
*
*
* @author
*/
public interface ListADT<T> extends CollectionADT<T> {
/**
* Adds the specified element to the list at the front
*
* @param element: the element to be added
*
*/
public void addFirst(T element);
/**
* Adds the specified element to the end of the list
*
* @param element: the element to be added
*/
public void addLast(T element);
/**
* Adds the specified element to the list after the existing element
*
* @param existing: the element that is in the list already
* @param element: the element to be added
* @throws ElementNotFoundException if existing isn't in the list
*/
public void addAfter(T existing, T element) throws ElementNotFoundException,
EmptyCollectionException;
/**
* Removes and returns the specified element
*
* @return the element specified
* @throws EmptyCollectionException
* @throws ElementNotFoundException
*/
public T remove(T element) throws EmptyCollectionException, ElementNotFoundException;
/**
* Removes and returns the first element
*
* @return the first element in the list
* @throws EmptyCollectionException
*/
public T removeFirst() throws EmptyCollectionException;
/**
* Removes and returns the last element
*
* @return the last element in the list
* @throws EmptyCollectionException
*/
public T removeLast() throws EmptyCollectionException;
/**
* Returns (without removing) the first element in the list
*
* @return element at the beginning of the list
* @throws EmptyCollectionException
*/
public T first() throws EmptyCollectionException;
/**
* Returns (without removing) the last element in the list
*
* @return element at the end of the list
* @throws EmptyCollectionException
*/
public T last() throws EmptyCollectionException;
/**
* Return whether the list contains the given element.
*
* @param element
* @return
* @throws EmptyCollectionException
*/
public boolean contains(T element) throws EmptyCollectionException;
/**
* Returns the index of the given element.
*
* @param element
* @return the index of the element, or -1 if not found
*/
public int indexOf(T element);
/**
* Return the element at the given index of a list.
*
* @param element
* @return
* @throws EmptyCollectionException
*/
public T get(int index) throws EmptyCollectionException, InvalidArgumentException;
/**
* Set the at the given index of a list.
*
* @param element
* @return
* @throws EmptyCollectionException
*/
public void set(int index, T element) throws EmptyCollectionException, InvalidArgumentException;
}
**********************************************
package ADTs;
import Exceptions.EmptyCollectionException;
import Exceptions.QueueOverflowException;
public interface QueueADT<T> extends CollectionADT<T> {
public void enqueue(T element) throws QueueOverflowException;
public T dequeue() throws EmptyCollectionException;
public T peek() throws EmptyCollectionException;
}
***** Work below please******
package DataStructures;
import ADTs.*;
import Exceptions.*;
public class ArrayQueue {
}
***********************************************************
package DataStructures;
import Exceptions.*;
import org.junit.Test;
import static org.junit.Assert.*;
public class ArrayQueueTest {
ArrayQueue<Integer> list = new ArrayQueue<Integer>(10);
@Test
public void testArrayQueue() {
// LinkedList
assertEquals(0, list.size());
list = new ArrayQueue<Integer>();
assertEquals(0, list.size());
}
@Test
public void testIsEmpty() {
assertTrue(list.isEmpty());
}
@Test
public void testSize() {
assertEquals(0, list.size());
try {
list.enqueue(1);
assertEquals(1, list.size());
list.enqueue(2);
assertEquals(2, list.size());
} catch (Exception e) {
fail("Shoud not throw exception here: " + e.toString());
}
try {
list.dequeue();
assertEquals(1, list.size());
list.dequeue();
assertEquals(0, list.size());
} catch (EmptyCollectionException e) {
fail("EmptyCollectionException should not be thrown here.");
}
}
@Test
public void testEnqueue() {
try {
list.enqueue(1);
} catch (Exception e) {
fail("Exception should not be thrown here: " + e.toString());
}
assertEquals(1, list.size());
try {
assertEquals(1, list.peek().intValue());
} catch (Exception e) {
fail("Exception should not be thrown here.");
}
try {
list.enqueue(2);
} catch (Exception e) {
fail("Exception should not be thrown here: " + e.toString());
}
assertEquals(2, list.size());
try {
assertEquals(1, list.peek().intValue());
} catch (Exception e) {
fail("Exception should not be thrown here: " + e.toString());
}
}
@Test
public void testDequeue() {
try {
list.enqueue(1);
list.enqueue(2);
list.enqueue(3);
} catch (Exception e) {
fail("Exception should not be thrown here: " + e.toString());
}
try {
assertEquals(3, list.size());
Integer out = list.dequeue();
assertEquals(1, out.intValue());
assertEquals(2, list.size());
} catch (Exception e) {
fail("Exception should not be thrown here.");
}
try {
assertEquals(2, list.size());
Integer out = list.dequeue();
assertEquals(2, out.intValue());
assertEquals(1, list.size());
} catch (Exception e) {
fail("Exception should not be thrown here.");
}
try {
Integer out = list.dequeue();
assertEquals(3, out.intValue());
assertEquals(0, list.size());
} catch (Exception e) {
fail("Exception should not be thrown here.");
}
try {
list.dequeue();
} catch (Exception e) {
assertTrue("EmptyCollectionException should be thrown here.", e instanceof
EmptyCollectionException);
}
}
@Test
public void testPeek() {
try {
list.enqueue(1);
} catch (Exception e) {
fail("Exception should not be thrown here: " + e.toString());
}
try {
assertEquals(1, list.size());
assertEquals(1, list.peek().intValue());
} catch (Exception e) {
fail("Exception should not be thrown here.");
}
try {
list.enqueue(2);
} catch (Exception e) {
fail("Exception should not be thrown here: " + e.toString());
}
try {
assertEquals(2, list.size());
assertEquals(1, list.peek().intValue());
list.dequeue();
assertEquals(2, list.peek().intValue());
} catch (Exception e) {
fail("Exception should not be thrown here.");
}
try {
list.dequeue();
} catch (Exception e) {
fail("Exception should not be thrown here: " + e.getMessage());
}
try {
list.peek();
} catch (Exception e) {
assertTrue("EmptyCollectionException should be thrown here.", e instanceof
EmptyCollectionException);
} }}
These are the files in the project -

More Related Content

Similar to package ADTs public interface CollectionADTltTgt .pdf

Complete the class ArraySet1java which implements the SetA.pdf
Complete the class ArraySet1java which implements the SetA.pdfComplete the class ArraySet1java which implements the SetA.pdf
Complete the class ArraySet1java which implements the SetA.pdf
abbecindia
 
Note- Can someone help me with the public boolean isEmpty()- public bo.pdf
Note- Can someone help me with the public boolean isEmpty()- public bo.pdfNote- Can someone help me with the public boolean isEmpty()- public bo.pdf
Note- Can someone help me with the public boolean isEmpty()- public bo.pdf
Augstore
 
import java-util--- public class MyLinkedList{ public static void.pdf
import java-util---  public class MyLinkedList{    public static void.pdfimport java-util---  public class MyLinkedList{    public static void.pdf
import java-util--- public class MyLinkedList{ public static void.pdf
asarudheen07
 
I need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdfI need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdf
fonecomp
 
please read below it will tell you what we are using L.pdf
please read below it will tell you what we are using   L.pdfplease read below it will tell you what we are using   L.pdf
please read below it will tell you what we are using L.pdf
ankit11134
 
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxNew folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
curwenmichaela
 
Please create the appropriate JUnit test cases to thoroughly.pdf
Please create the appropriate JUnit test cases to thoroughly.pdfPlease create the appropriate JUnit test cases to thoroughly.pdf
Please create the appropriate JUnit test cases to thoroughly.pdf
kitty811
 
please read the steps below and it will tell you what we usi.pdf
please read the steps below and it will tell you what we usi.pdfplease read the steps below and it will tell you what we usi.pdf
please read the steps below and it will tell you what we usi.pdf
aggarwalopticalsco
 
Note- Can someone help me with the private E get(int index- int curren (1).docx
Note- Can someone help me with the private E get(int index- int curren (1).docxNote- Can someone help me with the private E get(int index- int curren (1).docx
Note- Can someone help me with the private E get(int index- int curren (1).docx
VictorzH8Bondx
 
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
arshin9
 
Please do parts labeled TODO LinkedList.java Replace.pdf
Please do parts labeled TODO LinkedList.java Replace.pdfPlease do parts labeled TODO LinkedList.java Replace.pdf
Please do parts labeled TODO LinkedList.java Replace.pdf
aioils
 
we using java dynamicArray package modellinearpub imp.pdf
we using java dynamicArray    package modellinearpub   imp.pdfwe using java dynamicArray    package modellinearpub   imp.pdf
we using java dynamicArray package modellinearpub imp.pdf
adityagupta3310
 
public class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdfpublic class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdf
accostinternational
 
Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfGiven below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdf
info430661
 
Note- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdfNote- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdf
Stewart29UReesa
 
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdfLabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
fantasiatheoutofthef
 
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdfHow do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
mail931892
 

Similar to package ADTs public interface CollectionADTltTgt .pdf (20)

Complete the class ArraySet1java which implements the SetA.pdf
Complete the class ArraySet1java which implements the SetA.pdfComplete the class ArraySet1java which implements the SetA.pdf
Complete the class ArraySet1java which implements the SetA.pdf
 
Note- Can someone help me with the public boolean isEmpty()- public bo.pdf
Note- Can someone help me with the public boolean isEmpty()- public bo.pdfNote- Can someone help me with the public boolean isEmpty()- public bo.pdf
Note- Can someone help me with the public boolean isEmpty()- public bo.pdf
 
import java-util--- public class MyLinkedList{ public static void.pdf
import java-util---  public class MyLinkedList{    public static void.pdfimport java-util---  public class MyLinkedList{    public static void.pdf
import java-util--- public class MyLinkedList{ public static void.pdf
 
I need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdfI need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdf
 
please read below it will tell you what we are using L.pdf
please read below it will tell you what we are using   L.pdfplease read below it will tell you what we are using   L.pdf
please read below it will tell you what we are using L.pdf
 
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxNew folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
 
Please create the appropriate JUnit test cases to thoroughly.pdf
Please create the appropriate JUnit test cases to thoroughly.pdfPlease create the appropriate JUnit test cases to thoroughly.pdf
Please create the appropriate JUnit test cases to thoroughly.pdf
 
please read the steps below and it will tell you what we usi.pdf
please read the steps below and it will tell you what we usi.pdfplease read the steps below and it will tell you what we usi.pdf
please read the steps below and it will tell you what we usi.pdf
 
Note- Can someone help me with the private E get(int index- int curren (1).docx
Note- Can someone help me with the private E get(int index- int curren (1).docxNote- Can someone help me with the private E get(int index- int curren (1).docx
Note- Can someone help me with the private E get(int index- int curren (1).docx
 
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
 
Please do parts labeled TODO LinkedList.java Replace.pdf
Please do parts labeled TODO LinkedList.java Replace.pdfPlease do parts labeled TODO LinkedList.java Replace.pdf
Please do parts labeled TODO LinkedList.java Replace.pdf
 
we using java dynamicArray package modellinearpub imp.pdf
we using java dynamicArray    package modellinearpub   imp.pdfwe using java dynamicArray    package modellinearpub   imp.pdf
we using java dynamicArray package modellinearpub imp.pdf
 
public class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdfpublic class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdf
 
For this lab you will complete the class MyArrayList by implementing.pdf
For this lab you will complete the class MyArrayList by implementing.pdfFor this lab you will complete the class MyArrayList by implementing.pdf
For this lab you will complete the class MyArrayList by implementing.pdf
 
Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfGiven below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdf
 
Please add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docxPlease add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docx
 
Note- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdfNote- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdf
 
import java.util.;public class FirstChars {    public static vo.pdf
import java.util.;public class FirstChars {    public static vo.pdfimport java.util.;public class FirstChars {    public static vo.pdf
import java.util.;public class FirstChars {    public static vo.pdf
 
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdfLabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
 
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdfHow do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
 

More from syedabdul78662

Other map symbols on topographic maps Occasionally you will.pdf
Other map symbols on topographic maps Occasionally you will.pdfOther map symbols on topographic maps Occasionally you will.pdf
Other map symbols on topographic maps Occasionally you will.pdf
syedabdul78662
 
Orvilie borrowed 25000 from his friend Wilbur Orvile sign.pdf
Orvilie borrowed 25000 from his friend Wilbur Orvile sign.pdfOrvilie borrowed 25000 from his friend Wilbur Orvile sign.pdf
Orvilie borrowed 25000 from his friend Wilbur Orvile sign.pdf
syedabdul78662
 
Organizational context The organizational context for this .pdf
Organizational context  The organizational context for this .pdfOrganizational context  The organizational context for this .pdf
Organizational context The organizational context for this .pdf
syedabdul78662
 
Part 1 LinkedList Create a file named LinkedListpy I.pdf
Part 1  LinkedList  Create a file named LinkedListpy  I.pdfPart 1  LinkedList  Create a file named LinkedListpy  I.pdf
Part 1 LinkedList Create a file named LinkedListpy I.pdf
syedabdul78662
 
Part 1 The company has three branches two in Europe and o.pdf
Part 1   The company has three branches two in Europe and o.pdfPart 1   The company has three branches two in Europe and o.pdf
Part 1 The company has three branches two in Europe and o.pdf
syedabdul78662
 

More from syedabdul78662 (20)

Oxidase neg Indole neg VP pos Citrate pos Motile.pdf
Oxidase  neg Indole  neg VP  pos Citrate  pos Motile.pdfOxidase  neg Indole  neg VP  pos Citrate  pos Motile.pdf
Oxidase neg Indole neg VP pos Citrate pos Motile.pdf
 
Other map symbols on topographic maps Occasionally you will.pdf
Other map symbols on topographic maps Occasionally you will.pdfOther map symbols on topographic maps Occasionally you will.pdf
Other map symbols on topographic maps Occasionally you will.pdf
 
Osprey Corporation stock is owned by Pedro and Pittro who a.pdf
Osprey Corporation stock is owned by Pedro and Pittro who a.pdfOsprey Corporation stock is owned by Pedro and Pittro who a.pdf
Osprey Corporation stock is owned by Pedro and Pittro who a.pdf
 
ourism is extremely important to the economy of Florida Hot.pdf
ourism is extremely important to the economy of Florida Hot.pdfourism is extremely important to the economy of Florida Hot.pdf
ourism is extremely important to the economy of Florida Hot.pdf
 
Orvilie borrowed 25000 from his friend Wilbur Orvile sign.pdf
Orvilie borrowed 25000 from his friend Wilbur Orvile sign.pdfOrvilie borrowed 25000 from his friend Wilbur Orvile sign.pdf
Orvilie borrowed 25000 from his friend Wilbur Orvile sign.pdf
 
Our story begins at the Pearson Cooking Academy where many n.pdf
Our story begins at the Pearson Cooking Academy where many n.pdfOur story begins at the Pearson Cooking Academy where many n.pdf
Our story begins at the Pearson Cooking Academy where many n.pdf
 
Owen is a medical researcher who will receive bonus pay base.pdf
Owen is a medical researcher who will receive bonus pay base.pdfOwen is a medical researcher who will receive bonus pay base.pdf
Owen is a medical researcher who will receive bonus pay base.pdf
 
Oriole Company had the following assets on January 1 2025 .pdf
Oriole Company had the following assets on January 1 2025 .pdfOriole Company had the following assets on January 1 2025 .pdf
Oriole Company had the following assets on January 1 2025 .pdf
 
Organizational context The organizational context for this .pdf
Organizational context  The organizational context for this .pdfOrganizational context  The organizational context for this .pdf
Organizational context The organizational context for this .pdf
 
Overtime Hours Worked A random sample of 12 registered nurse.pdf
Overtime Hours Worked A random sample of 12 registered nurse.pdfOvertime Hours Worked A random sample of 12 registered nurse.pdf
Overtime Hours Worked A random sample of 12 registered nurse.pdf
 
Organizasyon Teorisi gnmz Organizasyonlarnn anlalmasnda .pdf
Organizasyon Teorisi gnmz Organizasyonlarnn anlalmasnda .pdfOrganizasyon Teorisi gnmz Organizasyonlarnn anlalmasnda .pdf
Organizasyon Teorisi gnmz Organizasyonlarnn anlalmasnda .pdf
 
Over the next decades sea level will rise at a constant ra.pdf
Over the next decades sea level will rise at a constant ra.pdfOver the next decades sea level will rise at a constant ra.pdf
Over the next decades sea level will rise at a constant ra.pdf
 
Over the years technology has changed rapidly and made our .pdf
Over the years technology has changed rapidly and made our .pdfOver the years technology has changed rapidly and made our .pdf
Over the years technology has changed rapidly and made our .pdf
 
Over the past two decades local governments have increasing.pdf
Over the past two decades local governments have increasing.pdfOver the past two decades local governments have increasing.pdf
Over the past two decades local governments have increasing.pdf
 
Over the past 1015 years the ways that insurance companies.pdf
Over the past 1015 years the ways that insurance companies.pdfOver the past 1015 years the ways that insurance companies.pdf
Over the past 1015 years the ways that insurance companies.pdf
 
Part 1 Create a 4 to 5page BCC Enterprise Information Secu.pdf
Part 1 Create a 4 to 5page BCC Enterprise Information Secu.pdfPart 1 Create a 4 to 5page BCC Enterprise Information Secu.pdf
Part 1 Create a 4 to 5page BCC Enterprise Information Secu.pdf
 
Part 1 Find a Canadian companyorganization Canadian mea.pdf
Part 1 Find a Canadian companyorganization Canadian mea.pdfPart 1 Find a Canadian companyorganization Canadian mea.pdf
Part 1 Find a Canadian companyorganization Canadian mea.pdf
 
Part 1 LinkedList Create a file named LinkedListpy I.pdf
Part 1  LinkedList  Create a file named LinkedListpy  I.pdfPart 1  LinkedList  Create a file named LinkedListpy  I.pdf
Part 1 LinkedList Create a file named LinkedListpy I.pdf
 
Part 1 The company has three branches two in Europe and o.pdf
Part 1   The company has three branches two in Europe and o.pdfPart 1   The company has three branches two in Europe and o.pdf
Part 1 The company has three branches two in Europe and o.pdf
 
Para reducir la desigualdad y la pobreza en una economa el.pdf
Para reducir la desigualdad y la pobreza en una economa el.pdfPara reducir la desigualdad y la pobreza en una economa el.pdf
Para reducir la desigualdad y la pobreza en una economa el.pdf
 

Recently uploaded

Recently uploaded (20)

Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matrices
 
How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
Morse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxMorse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptx
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
 
Benefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational ResourcesBenefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational Resources
 
Keeping Your Information Safe with Centralized Security Services
Keeping Your Information Safe with Centralized Security ServicesKeeping Your Information Safe with Centralized Security Services
Keeping Your Information Safe with Centralized Security Services
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
 
B.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdfB.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdf
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
 
Open Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPointOpen Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPoint
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
 

package ADTs public interface CollectionADTltTgt .pdf

  • 1. package ADTs; public interface CollectionADT<T> { public boolean isEmpty(); public int size(); @Override public String toString(); } ********************************************************** package ADTs; import Exceptions.*; /** * An interface for an ordered (NOT SORTED) List * Elements stay in the order they are put in to the list * For use in Data Structures & Algorithms * * * @author */ public interface ListADT<T> extends CollectionADT<T> { /** * Adds the specified element to the list at the front * * @param element: the element to be added * */ public void addFirst(T element); /** * Adds the specified element to the end of the list * * @param element: the element to be added */ public void addLast(T element); /** * Adds the specified element to the list after the existing element * * @param existing: the element that is in the list already * @param element: the element to be added * @throws ElementNotFoundException if existing isn't in the list */ public void addAfter(T existing, T element) throws ElementNotFoundException, EmptyCollectionException; /**
  • 2. * Removes and returns the specified element * * @return the element specified * @throws EmptyCollectionException * @throws ElementNotFoundException */ public T remove(T element) throws EmptyCollectionException, ElementNotFoundException; /** * Removes and returns the first element * * @return the first element in the list * @throws EmptyCollectionException */ public T removeFirst() throws EmptyCollectionException; /** * Removes and returns the last element * * @return the last element in the list * @throws EmptyCollectionException */ public T removeLast() throws EmptyCollectionException; /** * Returns (without removing) the first element in the list * * @return element at the beginning of the list * @throws EmptyCollectionException */ public T first() throws EmptyCollectionException; /** * Returns (without removing) the last element in the list * * @return element at the end of the list * @throws EmptyCollectionException */ public T last() throws EmptyCollectionException; /** * Return whether the list contains the given element. * * @param element * @return * @throws EmptyCollectionException */
  • 3. public boolean contains(T element) throws EmptyCollectionException; /** * Returns the index of the given element. * * @param element * @return the index of the element, or -1 if not found */ public int indexOf(T element); /** * Return the element at the given index of a list. * * @param element * @return * @throws EmptyCollectionException */ public T get(int index) throws EmptyCollectionException, InvalidArgumentException; /** * Set the at the given index of a list. * * @param element * @return * @throws EmptyCollectionException */ public void set(int index, T element) throws EmptyCollectionException, InvalidArgumentException; } ********************************************** package ADTs; import Exceptions.EmptyCollectionException; import Exceptions.QueueOverflowException; public interface QueueADT<T> extends CollectionADT<T> { public void enqueue(T element) throws QueueOverflowException; public T dequeue() throws EmptyCollectionException; public T peek() throws EmptyCollectionException; } ***** Work below please****** package DataStructures; import ADTs.*; import Exceptions.*; public class ArrayQueue { } *********************************************************** package DataStructures;
  • 4. import Exceptions.*; import org.junit.Test; import static org.junit.Assert.*; public class ArrayQueueTest { ArrayQueue<Integer> list = new ArrayQueue<Integer>(10); @Test public void testArrayQueue() { // LinkedList assertEquals(0, list.size()); list = new ArrayQueue<Integer>(); assertEquals(0, list.size()); } @Test public void testIsEmpty() { assertTrue(list.isEmpty()); } @Test public void testSize() { assertEquals(0, list.size()); try { list.enqueue(1); assertEquals(1, list.size()); list.enqueue(2); assertEquals(2, list.size()); } catch (Exception e) { fail("Shoud not throw exception here: " + e.toString()); } try { list.dequeue(); assertEquals(1, list.size()); list.dequeue(); assertEquals(0, list.size()); } catch (EmptyCollectionException e) { fail("EmptyCollectionException should not be thrown here."); } } @Test public void testEnqueue() { try { list.enqueue(1); } catch (Exception e) { fail("Exception should not be thrown here: " + e.toString());
  • 5. } assertEquals(1, list.size()); try { assertEquals(1, list.peek().intValue()); } catch (Exception e) { fail("Exception should not be thrown here."); } try { list.enqueue(2); } catch (Exception e) { fail("Exception should not be thrown here: " + e.toString()); } assertEquals(2, list.size()); try { assertEquals(1, list.peek().intValue()); } catch (Exception e) { fail("Exception should not be thrown here: " + e.toString()); } } @Test public void testDequeue() { try { list.enqueue(1); list.enqueue(2); list.enqueue(3); } catch (Exception e) { fail("Exception should not be thrown here: " + e.toString()); } try { assertEquals(3, list.size()); Integer out = list.dequeue(); assertEquals(1, out.intValue()); assertEquals(2, list.size()); } catch (Exception e) { fail("Exception should not be thrown here."); } try { assertEquals(2, list.size()); Integer out = list.dequeue(); assertEquals(2, out.intValue()); assertEquals(1, list.size()); } catch (Exception e) {
  • 6. fail("Exception should not be thrown here."); } try { Integer out = list.dequeue(); assertEquals(3, out.intValue()); assertEquals(0, list.size()); } catch (Exception e) { fail("Exception should not be thrown here."); } try { list.dequeue(); } catch (Exception e) { assertTrue("EmptyCollectionException should be thrown here.", e instanceof EmptyCollectionException); } } @Test public void testPeek() { try { list.enqueue(1); } catch (Exception e) { fail("Exception should not be thrown here: " + e.toString()); } try { assertEquals(1, list.size()); assertEquals(1, list.peek().intValue()); } catch (Exception e) { fail("Exception should not be thrown here."); } try { list.enqueue(2); } catch (Exception e) { fail("Exception should not be thrown here: " + e.toString()); } try { assertEquals(2, list.size()); assertEquals(1, list.peek().intValue()); list.dequeue(); assertEquals(2, list.peek().intValue()); } catch (Exception e) { fail("Exception should not be thrown here."); }
  • 7. try { list.dequeue(); } catch (Exception e) { fail("Exception should not be thrown here: " + e.getMessage()); } try { list.peek(); } catch (Exception e) { assertTrue("EmptyCollectionException should be thrown here.", e instanceof EmptyCollectionException); } }} These are the files in the project -