SlideShare a Scribd company logo
1 of 13
JAVA
Demonstrate the use of your APL in a PartB_Driver class by doing the following. Create a static
method called removeConsecutiveDuplicates that removes any consecutive duplicate strings
from an array positional list of Strings and returns the number of strings left after the removal.
After calling the method, the positional list parameter should contain the same sequence of
strings as before but with any consecutive duplicates removed. Illustrate your method using the
following sets of strings and display the content of the list after executing the method.
NOTE: You MUST use a combination/variation of ALL the add and set methods (AddFirst,
AddLast, AddBefore, AddAfter, and set) in creating one of the following original lists.
- harry ron tom tom tom hermione
- harry harry tom ron mary harry
- tom ron harry hermione mary
- mary mary tom james hermione hermione james harry harry harry
You MUST NOT use any other auxiliary data structure e.g., arrays in your implementation
ofremoveConsecutiveDuplicates.
Sample Output (for last set of Strings)
Original positional list:
[0] mary [1] mary [2] tom [3] james [4] hermione [5] hermione [6] james [7] harry [8] harry [9]
harry
APL.java
public class ArrayPositionalList<E> implements PositionalList<E> {
private static class ArrPos<E> implements Position<E> {
private int index;
private E element;
public ArrPos(E e, int i) {
index = i;
element = e;
}
public E getElement() throws IllegalStateException {
if (index == -1) {
throw new IllegalStateException("Position no longer valid");
}
return element;
}
public void setElement(E e) {
element = e;
}
public int getIndex() {
return index;
}
public void setIndex(int i) {
index = i;
}
}
public static final int CAPACITY = 16;
private ArrPos<E>[] data;
private int size = 0;
public ArrayPositionalList() {
this(CAPACITY);
}
public ArrayPositionalList(int capacity) {
data = (ArrPos<E>[]) new ArrPos[capacity];
}
@Override
public int size() {
return size;
}
@Override
public boolean isEmpty() {
return size == 0;
}
@Override
public Position first() {
if (!isEmpty())
return data[0];
return null;
}
@Override
public Position last() {
if (!isEmpty())
return data[size - 1];
return null;
}
@Override
public Position before(Position p) throws IllegalArgumentException {
if (p.getIndex() > 0 && p.getIndex() < size) {
return data[p.getIndex() - 1];
}
if (p.getIndex() == 0)
return null;
throw new IllegalArgumentException();
}
@Override
public Position after(Position p) throws IllegalArgumentException {
if (p.getIndex() >= 0 && p.getIndex() < size - 1) {
return data[p.getIndex() + 1];
}
if (p.getIndex() == size - 1)
return null;
throw new IllegalArgumentException();
}
@Override
public Position addFirst(E e) {
if (size < data.length) {
for (int i = size - 1; i >= 0; i--) {
data[i + 1] = data[i];
data[i + 1].setIndex(data[i + 1].getIndex() + 1);
}
data[0] = new ArrPos<E>(e, 0);
size++;
return data[0];
}
return null;
}
@Override
public Position addLast(E e) {
if (size < data.length) {
data[size] = new ArrPos<E>(e, size);
size++;
return data[size - 1];
}
return null;
}
@Override
public Position addBefore(Position p, E e) throws IllegalArgumentException {
int value = p.getIndex();
if (size < data.length) {
for (int i = size - 1; i >= value; i--) {
data[i].setIndex(data[i].getIndex() + 1);
data[i + 1] = data[i];
}
data[value] = new ArrPos<E>(e, value);
size++;
return data[value];
}
return null;
}
@Override
public Position addAfter(Position p, E e) throws IllegalArgumentException {
int value = p.getIndex();
if (value >= 0 && value < size) {
if (size < data.length) {
for (int i = size - 1; i > value; i--) {
data[i].setIndex(data[i].getIndex() + 1);
data[i + 1] = data[i];
}
data[value + 1] = new ArrPos<E>(e, value + 1);
size++;
return data[value + 1];
}
return null;
}
throw new IllegalArgumentException();
}
@Override
public E set(Position p, E e) throws IllegalArgumentException {
int value = p.getIndex();
if (value >= 0 && value < size) {
E item = (E) data[value].getElement();
data[value] = new ArrPos<E>(e, value);
return item;
} else {
throw new IllegalArgumentException();
}
}
@Override
public E remove(Position p) throws IllegalArgumentException {
int value = p.getIndex();
if (value >= 0 && value < size) {
E item = (E) data[value].getElement();
for (int i = value; i < size - 1; i++) {
data[i].setIndex(data[i].getIndex() - 1);
data[i] = data[i + 1];
}
return item;
}
throw new IllegalArgumentException();
}
@Override
public String toString() {
String result = "";
for (int i = 0; i < size; i++) {
ArrPos<E> l = data[i];
result = result + "[" + l.getIndex() + "] " + l.element.toString() + " ";
}
return result;
}
}
Position.java
public interface Position<E> {
/**
* Returns the element stored at this position.
*
* @return the stored element
* @throws IllegalStateException if position no longer valid
*/
E getElement() throws IllegalStateException;
public int getIndex();
}
PositionalList.java
public interface PositionalList<E> {
/**
* Returns the number of elements in the list.
* @return number of elements in the list
*/
int size();
/**
* Tests whether the list is empty.
* @return true if the list is empty, false otherwise
*/
boolean isEmpty();
/**
* Returns the first Position in the list.
*
* @return the first Position in the list (or null, if empty)
*/
Position<E> first();
/**
* Returns the last Position in the list.
*
* @return the last Position in the list (or null, if empty)
*/
Position<E> last();
/**
* Returns the Position immediately before Position p.
* @param p a Position of the list
* @return the Position of the preceding element (or null, if p is first)
* @throws IllegalArgumentException if p is not a valid position for this list
*/
Position<E> before(Position<E> p) throws IllegalArgumentException;
/**
* Returns the Position immediately after Position p.
* @param p a Position of the list
* @return the Position of the following element (or null, if p is last)
* @throws IllegalArgumentException if p is not a valid position for this list
*/
Position<E> after(Position<E> p) throws IllegalArgumentException;
/**
* Inserts an element at the front of the list.
*
* @param e the new element
* @return the Position representing the location of the new element
*/
Position<E> addFirst(E e);
/**
* Inserts an element at the back of the list.
*
* @param e the new element
* @return the Position representing the location of the new element
*/
Position<E> addLast(E e);
/**
* Inserts an element immediately before the given Position.
*
* @param p the Position before which the insertion takes place
* @param e the new element
* @return the Position representing the location of the new element
* @throws IllegalArgumentException if p is not a valid position for this list
*/
Position<E> addBefore(Position<E> p, E e)
throws IllegalArgumentException;
/**
* Inserts an element immediately after the given Position.
*
* @param p the Position after which the insertion takes place
* @param e the new element
* @return the Position representing the location of the new element
* @throws IllegalArgumentException if p is not a valid position for this list
*/
Position<E> addAfter(Position<E> p, E e)
throws IllegalArgumentException;
/**
* Replaces the element stored at the given Position and returns the replaced element.
*
* @param p the Position of the element to be replaced
* @param e the new element
* @return the replaced element
* @throws IllegalArgumentException if p is not a valid position for this list
*/
E set(Position<E> p, E e) throws IllegalArgumentException;
/**
* Removes the element stored at the given Position and returns it.
* The given position is invalidated as a result.
*
* @param p the Position of the element to be removed
* @return the removed element
* @throws IllegalArgumentException if p is not a valid position for this list
*/
E remove(Position<E> p) throws IllegalArgumentException;
}
JAVA Demonstrate the use of your APL in a PartB_Driver class by doing.docx

More Related Content

Similar to JAVA Demonstrate the use of your APL in a PartB_Driver class by doing.docx

For the code below complete the preOrder() method so that it perform.pdf
For the code below complete the preOrder() method so that it perform.pdfFor the code below complete the preOrder() method so that it perform.pdf
For the code below complete the preOrder() method so that it perform.pdfxlynettalampleyxc
 
Implement the additional 5 methods as indicated in the LinkedList fi.pdf
Implement the additional 5 methods as indicated in the LinkedList fi.pdfImplement the additional 5 methods as indicated in the LinkedList fi.pdf
Implement the additional 5 methods as indicated in the LinkedList fi.pdffootstatus
 
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdfClass DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdfxlynettalampleyxc
 
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.pdffashiongallery1
 
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdfJAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdfarpaqindia
 
Please complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docxPlease complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docxcgraciela1
 
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).docxVictorzH8Bondx
 
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.pdfStewart29UReesa
 
STAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfSTAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfbabitasingh698417
 
public class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdfpublic class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdfaccostinternational
 
we using java code DynamicArrayjava Replace all .pdf
we using java code   DynamicArrayjava   Replace all .pdfwe using java code   DynamicArrayjava   Replace all .pdf
we using java code DynamicArrayjava Replace all .pdfgudduraza28
 
The LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfThe LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfmalavshah9013
 
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.pdfabbecindia
 
Java Foundations StackADT-java --- - Defines the interface to a stack.docx
Java Foundations StackADT-java ---  - Defines the interface to a stack.docxJava Foundations StackADT-java ---  - Defines the interface to a stack.docx
Java Foundations StackADT-java --- - Defines the interface to a stack.docxVictorXUQGloverl
 
File LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfFile LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfConint29
 
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.pdfAugstore
 
package ADTs public interface CollectionADTltTgt .pdf
package ADTs public interface CollectionADTltTgt      .pdfpackage ADTs public interface CollectionADTltTgt      .pdf
package ADTs public interface CollectionADTltTgt .pdfsyedabdul78662
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdffreddysarabia1
 
Write a program to find the number of comparisons using the binary se.docx
 Write a program to find the number of comparisons using the binary se.docx Write a program to find the number of comparisons using the binary se.docx
Write a program to find the number of comparisons using the binary se.docxajoy21
 

Similar to JAVA Demonstrate the use of your APL in a PartB_Driver class by doing.docx (20)

For the code below complete the preOrder() method so that it perform.pdf
For the code below complete the preOrder() method so that it perform.pdfFor the code below complete the preOrder() method so that it perform.pdf
For the code below complete the preOrder() method so that it perform.pdf
 
Implement the additional 5 methods as indicated in the LinkedList fi.pdf
Implement the additional 5 methods as indicated in the LinkedList fi.pdfImplement the additional 5 methods as indicated in the LinkedList fi.pdf
Implement the additional 5 methods as indicated in the LinkedList fi.pdf
 
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdfClass DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.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
 
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdfJAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
 
Please complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docxPlease complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docx
 
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
 
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
 
STAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfSTAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdf
 
public class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdfpublic class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdf
 
we using java code DynamicArrayjava Replace all .pdf
we using java code   DynamicArrayjava   Replace all .pdfwe using java code   DynamicArrayjava   Replace all .pdf
we using java code DynamicArrayjava Replace all .pdf
 
The LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfThe LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.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
 
Java Foundations StackADT-java --- - Defines the interface to a stack.docx
Java Foundations StackADT-java ---  - Defines the interface to a stack.docxJava Foundations StackADT-java ---  - Defines the interface to a stack.docx
Java Foundations StackADT-java --- - Defines the interface to a stack.docx
 
Java Generics
Java GenericsJava Generics
Java Generics
 
File LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfFile LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.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
 
package ADTs public interface CollectionADTltTgt .pdf
package ADTs public interface CollectionADTltTgt      .pdfpackage ADTs public interface CollectionADTltTgt      .pdf
package ADTs public interface CollectionADTltTgt .pdf
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
 
Write a program to find the number of comparisons using the binary se.docx
 Write a program to find the number of comparisons using the binary se.docx Write a program to find the number of comparisons using the binary se.docx
Write a program to find the number of comparisons using the binary se.docx
 

More from GavinUJtMathist

License plate and driver's license are used as identifiers for individ.docx
License plate and driver's license are used as identifiers for individ.docxLicense plate and driver's license are used as identifiers for individ.docx
License plate and driver's license are used as identifiers for individ.docxGavinUJtMathist
 
Let X be uniformly distributed on -1-1-- Find the density of Y-Xk for.docx
Let X be uniformly distributed on -1-1-- Find the density of Y-Xk for.docxLet X be uniformly distributed on -1-1-- Find the density of Y-Xk for.docx
Let X be uniformly distributed on -1-1-- Find the density of Y-Xk for.docxGavinUJtMathist
 
Let X-Y be (discrete) random variables- (1) What is the value of i-1mj.docx
Let X-Y be (discrete) random variables- (1) What is the value of i-1mj.docxLet X-Y be (discrete) random variables- (1) What is the value of i-1mj.docx
Let X-Y be (discrete) random variables- (1) What is the value of i-1mj.docxGavinUJtMathist
 
Let X be a random variable distributed as Poisson distribution with me.docx
Let X be a random variable distributed as Poisson distribution with me.docxLet X be a random variable distributed as Poisson distribution with me.docx
Let X be a random variable distributed as Poisson distribution with me.docxGavinUJtMathist
 
Let V-W-X- and Y be independent- standard normal random variables- a-.docx
Let V-W-X- and Y be independent- standard normal random variables- a-.docxLet V-W-X- and Y be independent- standard normal random variables- a-.docx
Let V-W-X- and Y be independent- standard normal random variables- a-.docxGavinUJtMathist
 
Let the remaining lifetime at birth random variable T0 be exponential.docx
Let the remaining lifetime at birth random variable T0 be exponential.docxLet the remaining lifetime at birth random variable T0 be exponential.docx
Let the remaining lifetime at birth random variable T0 be exponential.docxGavinUJtMathist
 
Let A and B be two events defined on a sample space S such that p(A)-0.docx
Let A and B be two events defined on a sample space S such that p(A)-0.docxLet A and B be two events defined on a sample space S such that p(A)-0.docx
Let A and B be two events defined on a sample space S such that p(A)-0.docxGavinUJtMathist
 
Leslie-17- mother of 2 weeks old Milton- is a single mother who is new.docx
Leslie-17- mother of 2 weeks old Milton- is a single mother who is new.docxLeslie-17- mother of 2 weeks old Milton- is a single mother who is new.docx
Leslie-17- mother of 2 weeks old Milton- is a single mother who is new.docxGavinUJtMathist
 
Lee Manufacturing's value of operations is equal to $900 million after.docx
Lee Manufacturing's value of operations is equal to $900 million after.docxLee Manufacturing's value of operations is equal to $900 million after.docx
Lee Manufacturing's value of operations is equal to $900 million after.docxGavinUJtMathist
 
Lauren is a college sophomore majoring in business- This semester Laur.docx
Lauren is a college sophomore majoring in business- This semester Laur.docxLauren is a college sophomore majoring in business- This semester Laur.docx
Lauren is a college sophomore majoring in business- This semester Laur.docxGavinUJtMathist
 
Lab 8- The Endospore Stain Qovitien 1 at 1 In each column below- welec.docx
Lab 8- The Endospore Stain Qovitien 1 at 1 In each column below- welec.docxLab 8- The Endospore Stain Qovitien 1 at 1 In each column below- welec.docx
Lab 8- The Endospore Stain Qovitien 1 at 1 In each column below- welec.docxGavinUJtMathist
 
Know the risk groups- symptoms- signs- causes- preventions and treatme.docx
Know the risk groups- symptoms- signs- causes- preventions and treatme.docxKnow the risk groups- symptoms- signs- causes- preventions and treatme.docx
Know the risk groups- symptoms- signs- causes- preventions and treatme.docxGavinUJtMathist
 
Kindly answer all questions Thank you so much Question 3- Answer the.docx
Kindly answer all questions Thank you so much  Question 3- Answer the.docxKindly answer all questions Thank you so much  Question 3- Answer the.docx
Kindly answer all questions Thank you so much Question 3- Answer the.docxGavinUJtMathist
 
Kedzie Kord Company reported market price of its share as $ 50 per sha.docx
Kedzie Kord Company reported market price of its share as $ 50 per sha.docxKedzie Kord Company reported market price of its share as $ 50 per sha.docx
Kedzie Kord Company reported market price of its share as $ 50 per sha.docxGavinUJtMathist
 
Key MetricsStep 1- Write a sentence describing a takeaway from each co.docx
Key MetricsStep 1- Write a sentence describing a takeaway from each co.docxKey MetricsStep 1- Write a sentence describing a takeaway from each co.docx
Key MetricsStep 1- Write a sentence describing a takeaway from each co.docxGavinUJtMathist
 
John and Lynne have been working together as managers at British Imper.docx
John and Lynne have been working together as managers at British Imper.docxJohn and Lynne have been working together as managers at British Imper.docx
John and Lynne have been working together as managers at British Imper.docxGavinUJtMathist
 
k-k-M-1A-1 Tome kinis the fue departisint- Then calousate the percenta.docx
k-k-M-1A-1 Tome kinis the fue departisint- Then calousate the percenta.docxk-k-M-1A-1 Tome kinis the fue departisint- Then calousate the percenta.docx
k-k-M-1A-1 Tome kinis the fue departisint- Then calousate the percenta.docxGavinUJtMathist
 
Journal entry worksheet Income taxes for the year total $42-000 but wo.docx
Journal entry worksheet Income taxes for the year total $42-000 but wo.docxJournal entry worksheet Income taxes for the year total $42-000 but wo.docx
Journal entry worksheet Income taxes for the year total $42-000 but wo.docxGavinUJtMathist
 
java programming clemictis of the array mytust Seanner console - mew S.docx
java programming clemictis of the array mytust Seanner console - mew S.docxjava programming clemictis of the array mytust Seanner console - mew S.docx
java programming clemictis of the array mytust Seanner console - mew S.docxGavinUJtMathist
 
John resigned from an assurance engagement because his independence wa.docx
John resigned from an assurance engagement because his independence wa.docxJohn resigned from an assurance engagement because his independence wa.docx
John resigned from an assurance engagement because his independence wa.docxGavinUJtMathist
 

More from GavinUJtMathist (20)

License plate and driver's license are used as identifiers for individ.docx
License plate and driver's license are used as identifiers for individ.docxLicense plate and driver's license are used as identifiers for individ.docx
License plate and driver's license are used as identifiers for individ.docx
 
Let X be uniformly distributed on -1-1-- Find the density of Y-Xk for.docx
Let X be uniformly distributed on -1-1-- Find the density of Y-Xk for.docxLet X be uniformly distributed on -1-1-- Find the density of Y-Xk for.docx
Let X be uniformly distributed on -1-1-- Find the density of Y-Xk for.docx
 
Let X-Y be (discrete) random variables- (1) What is the value of i-1mj.docx
Let X-Y be (discrete) random variables- (1) What is the value of i-1mj.docxLet X-Y be (discrete) random variables- (1) What is the value of i-1mj.docx
Let X-Y be (discrete) random variables- (1) What is the value of i-1mj.docx
 
Let X be a random variable distributed as Poisson distribution with me.docx
Let X be a random variable distributed as Poisson distribution with me.docxLet X be a random variable distributed as Poisson distribution with me.docx
Let X be a random variable distributed as Poisson distribution with me.docx
 
Let V-W-X- and Y be independent- standard normal random variables- a-.docx
Let V-W-X- and Y be independent- standard normal random variables- a-.docxLet V-W-X- and Y be independent- standard normal random variables- a-.docx
Let V-W-X- and Y be independent- standard normal random variables- a-.docx
 
Let the remaining lifetime at birth random variable T0 be exponential.docx
Let the remaining lifetime at birth random variable T0 be exponential.docxLet the remaining lifetime at birth random variable T0 be exponential.docx
Let the remaining lifetime at birth random variable T0 be exponential.docx
 
Let A and B be two events defined on a sample space S such that p(A)-0.docx
Let A and B be two events defined on a sample space S such that p(A)-0.docxLet A and B be two events defined on a sample space S such that p(A)-0.docx
Let A and B be two events defined on a sample space S such that p(A)-0.docx
 
Leslie-17- mother of 2 weeks old Milton- is a single mother who is new.docx
Leslie-17- mother of 2 weeks old Milton- is a single mother who is new.docxLeslie-17- mother of 2 weeks old Milton- is a single mother who is new.docx
Leslie-17- mother of 2 weeks old Milton- is a single mother who is new.docx
 
Lee Manufacturing's value of operations is equal to $900 million after.docx
Lee Manufacturing's value of operations is equal to $900 million after.docxLee Manufacturing's value of operations is equal to $900 million after.docx
Lee Manufacturing's value of operations is equal to $900 million after.docx
 
Lauren is a college sophomore majoring in business- This semester Laur.docx
Lauren is a college sophomore majoring in business- This semester Laur.docxLauren is a college sophomore majoring in business- This semester Laur.docx
Lauren is a college sophomore majoring in business- This semester Laur.docx
 
Lab 8- The Endospore Stain Qovitien 1 at 1 In each column below- welec.docx
Lab 8- The Endospore Stain Qovitien 1 at 1 In each column below- welec.docxLab 8- The Endospore Stain Qovitien 1 at 1 In each column below- welec.docx
Lab 8- The Endospore Stain Qovitien 1 at 1 In each column below- welec.docx
 
Know the risk groups- symptoms- signs- causes- preventions and treatme.docx
Know the risk groups- symptoms- signs- causes- preventions and treatme.docxKnow the risk groups- symptoms- signs- causes- preventions and treatme.docx
Know the risk groups- symptoms- signs- causes- preventions and treatme.docx
 
Kindly answer all questions Thank you so much Question 3- Answer the.docx
Kindly answer all questions Thank you so much  Question 3- Answer the.docxKindly answer all questions Thank you so much  Question 3- Answer the.docx
Kindly answer all questions Thank you so much Question 3- Answer the.docx
 
Kedzie Kord Company reported market price of its share as $ 50 per sha.docx
Kedzie Kord Company reported market price of its share as $ 50 per sha.docxKedzie Kord Company reported market price of its share as $ 50 per sha.docx
Kedzie Kord Company reported market price of its share as $ 50 per sha.docx
 
Key MetricsStep 1- Write a sentence describing a takeaway from each co.docx
Key MetricsStep 1- Write a sentence describing a takeaway from each co.docxKey MetricsStep 1- Write a sentence describing a takeaway from each co.docx
Key MetricsStep 1- Write a sentence describing a takeaway from each co.docx
 
John and Lynne have been working together as managers at British Imper.docx
John and Lynne have been working together as managers at British Imper.docxJohn and Lynne have been working together as managers at British Imper.docx
John and Lynne have been working together as managers at British Imper.docx
 
k-k-M-1A-1 Tome kinis the fue departisint- Then calousate the percenta.docx
k-k-M-1A-1 Tome kinis the fue departisint- Then calousate the percenta.docxk-k-M-1A-1 Tome kinis the fue departisint- Then calousate the percenta.docx
k-k-M-1A-1 Tome kinis the fue departisint- Then calousate the percenta.docx
 
Journal entry worksheet Income taxes for the year total $42-000 but wo.docx
Journal entry worksheet Income taxes for the year total $42-000 but wo.docxJournal entry worksheet Income taxes for the year total $42-000 but wo.docx
Journal entry worksheet Income taxes for the year total $42-000 but wo.docx
 
java programming clemictis of the array mytust Seanner console - mew S.docx
java programming clemictis of the array mytust Seanner console - mew S.docxjava programming clemictis of the array mytust Seanner console - mew S.docx
java programming clemictis of the array mytust Seanner console - mew S.docx
 
John resigned from an assurance engagement because his independence wa.docx
John resigned from an assurance engagement because his independence wa.docxJohn resigned from an assurance engagement because his independence wa.docx
John resigned from an assurance engagement because his independence wa.docx
 

Recently uploaded

Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 

Recently uploaded (20)

Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 

JAVA Demonstrate the use of your APL in a PartB_Driver class by doing.docx

  • 1. JAVA Demonstrate the use of your APL in a PartB_Driver class by doing the following. Create a static method called removeConsecutiveDuplicates that removes any consecutive duplicate strings from an array positional list of Strings and returns the number of strings left after the removal. After calling the method, the positional list parameter should contain the same sequence of strings as before but with any consecutive duplicates removed. Illustrate your method using the following sets of strings and display the content of the list after executing the method. NOTE: You MUST use a combination/variation of ALL the add and set methods (AddFirst, AddLast, AddBefore, AddAfter, and set) in creating one of the following original lists. - harry ron tom tom tom hermione - harry harry tom ron mary harry - tom ron harry hermione mary - mary mary tom james hermione hermione james harry harry harry You MUST NOT use any other auxiliary data structure e.g., arrays in your implementation ofremoveConsecutiveDuplicates. Sample Output (for last set of Strings) Original positional list: [0] mary [1] mary [2] tom [3] james [4] hermione [5] hermione [6] james [7] harry [8] harry [9] harry APL.java public class ArrayPositionalList<E> implements PositionalList<E> { private static class ArrPos<E> implements Position<E> { private int index; private E element; public ArrPos(E e, int i) { index = i; element = e; }
  • 2. public E getElement() throws IllegalStateException { if (index == -1) { throw new IllegalStateException("Position no longer valid"); } return element; } public void setElement(E e) { element = e; } public int getIndex() { return index; } public void setIndex(int i) { index = i; } } public static final int CAPACITY = 16; private ArrPos<E>[] data; private int size = 0; public ArrayPositionalList() { this(CAPACITY); } public ArrayPositionalList(int capacity) {
  • 3. data = (ArrPos<E>[]) new ArrPos[capacity]; } @Override public int size() { return size; } @Override public boolean isEmpty() { return size == 0; } @Override public Position first() { if (!isEmpty()) return data[0]; return null; } @Override public Position last() { if (!isEmpty()) return data[size - 1]; return null; } @Override
  • 4. public Position before(Position p) throws IllegalArgumentException { if (p.getIndex() > 0 && p.getIndex() < size) { return data[p.getIndex() - 1]; } if (p.getIndex() == 0) return null; throw new IllegalArgumentException(); } @Override public Position after(Position p) throws IllegalArgumentException { if (p.getIndex() >= 0 && p.getIndex() < size - 1) { return data[p.getIndex() + 1]; } if (p.getIndex() == size - 1) return null; throw new IllegalArgumentException(); } @Override public Position addFirst(E e) { if (size < data.length) { for (int i = size - 1; i >= 0; i--) { data[i + 1] = data[i]; data[i + 1].setIndex(data[i + 1].getIndex() + 1);
  • 5. } data[0] = new ArrPos<E>(e, 0); size++; return data[0]; } return null; } @Override public Position addLast(E e) { if (size < data.length) { data[size] = new ArrPos<E>(e, size); size++; return data[size - 1]; } return null; } @Override public Position addBefore(Position p, E e) throws IllegalArgumentException { int value = p.getIndex(); if (size < data.length) { for (int i = size - 1; i >= value; i--) { data[i].setIndex(data[i].getIndex() + 1); data[i + 1] = data[i];
  • 6. } data[value] = new ArrPos<E>(e, value); size++; return data[value]; } return null; } @Override public Position addAfter(Position p, E e) throws IllegalArgumentException { int value = p.getIndex(); if (value >= 0 && value < size) { if (size < data.length) { for (int i = size - 1; i > value; i--) { data[i].setIndex(data[i].getIndex() + 1); data[i + 1] = data[i]; } data[value + 1] = new ArrPos<E>(e, value + 1); size++; return data[value + 1]; } return null; } throw new IllegalArgumentException();
  • 7. } @Override public E set(Position p, E e) throws IllegalArgumentException { int value = p.getIndex(); if (value >= 0 && value < size) { E item = (E) data[value].getElement(); data[value] = new ArrPos<E>(e, value); return item; } else { throw new IllegalArgumentException(); } } @Override public E remove(Position p) throws IllegalArgumentException { int value = p.getIndex(); if (value >= 0 && value < size) { E item = (E) data[value].getElement(); for (int i = value; i < size - 1; i++) { data[i].setIndex(data[i].getIndex() - 1); data[i] = data[i + 1]; } return item; }
  • 8. throw new IllegalArgumentException(); } @Override public String toString() { String result = ""; for (int i = 0; i < size; i++) { ArrPos<E> l = data[i]; result = result + "[" + l.getIndex() + "] " + l.element.toString() + " "; } return result; } } Position.java public interface Position<E> { /** * Returns the element stored at this position. * * @return the stored element * @throws IllegalStateException if position no longer valid */ E getElement() throws IllegalStateException; public int getIndex(); }
  • 9. PositionalList.java public interface PositionalList<E> { /** * Returns the number of elements in the list. * @return number of elements in the list */ int size(); /** * Tests whether the list is empty. * @return true if the list is empty, false otherwise */ boolean isEmpty(); /** * Returns the first Position in the list. * * @return the first Position in the list (or null, if empty) */ Position<E> first(); /** * Returns the last Position in the list. * * @return the last Position in the list (or null, if empty) */
  • 10. Position<E> last(); /** * Returns the Position immediately before Position p. * @param p a Position of the list * @return the Position of the preceding element (or null, if p is first) * @throws IllegalArgumentException if p is not a valid position for this list */ Position<E> before(Position<E> p) throws IllegalArgumentException; /** * Returns the Position immediately after Position p. * @param p a Position of the list * @return the Position of the following element (or null, if p is last) * @throws IllegalArgumentException if p is not a valid position for this list */ Position<E> after(Position<E> p) throws IllegalArgumentException; /** * Inserts an element at the front of the list. * * @param e the new element * @return the Position representing the location of the new element */ Position<E> addFirst(E e); /**
  • 11. * Inserts an element at the back of the list. * * @param e the new element * @return the Position representing the location of the new element */ Position<E> addLast(E e); /** * Inserts an element immediately before the given Position. * * @param p the Position before which the insertion takes place * @param e the new element * @return the Position representing the location of the new element * @throws IllegalArgumentException if p is not a valid position for this list */ Position<E> addBefore(Position<E> p, E e) throws IllegalArgumentException; /** * Inserts an element immediately after the given Position. * * @param p the Position after which the insertion takes place * @param e the new element * @return the Position representing the location of the new element * @throws IllegalArgumentException if p is not a valid position for this list
  • 12. */ Position<E> addAfter(Position<E> p, E e) throws IllegalArgumentException; /** * Replaces the element stored at the given Position and returns the replaced element. * * @param p the Position of the element to be replaced * @param e the new element * @return the replaced element * @throws IllegalArgumentException if p is not a valid position for this list */ E set(Position<E> p, E e) throws IllegalArgumentException; /** * Removes the element stored at the given Position and returns it. * The given position is invalidated as a result. * * @param p the Position of the element to be removed * @return the removed element * @throws IllegalArgumentException if p is not a valid position for this list */ E remove(Position<E> p) throws IllegalArgumentException; }