SlideShare a Scribd company logo
//Modifications highlighted in bold letters
//DropOutStack.java
import java.util.Arrays;
public class DropOutStack {
/**
* Defines the interface to a stack collection.
*
* @author Java Foundations
* @version 4.0
*/
public interface StackADT {
/**
* Adds the specified element to the top of this stack.
*
* @param element
* element to be pushed onto the stack
*/
public void push(T element);
/**
* Removes and returns the top element from this stack.
*
* @return the element removed from the stack
*/
public T pop();
/**
* Returns without removing the top element of this stack.
*
* @return the element on top of the stack
*/
public T peek();
/**
* Returns true if this stack contains no elements.
*
* @return true if the stack is empty
*/
public boolean isEmpty();
/**
* Returns the number of elements in this stack.
*
* @return the number of elements in the stack
*/
public int size();
/**
* Returns a string representation of this stack.
*
* @return a string representation of the stack
*/
public String toString();
}
/**
* Represents the situation in which a collection is empty.
*
* @author Java Foundations
* @version 4.0
*/
public static class EmptyCollectionException extends RuntimeException {
/**
* Sets up this exception with an appropriate message.
*
* @param collection
* the name of the collection
*/
public EmptyCollectionException(String collection) {
super("The " + collection + " is empty.");
}
}
/**
* Program entry point for stack testing.
*
* @param args
* Argument list.
*/
public static void main(String[] args) {
ArrayDropOutStack stack = new ArrayDropOutStack(4);
System.out.println("DROP-OUT STACK TESTING");
stack.push(1);
stack.push(2);
stack.push(3);
stack.push(4);
System.out.println("Stack : "+stack.toString());
System.out.println("pushing 5 element ");
stack.push(5);
System.out.println("Now stack elements");
System.out.println(stack.toString());
System.out.println("The size of the stack is: " + stack.size());
if (!stack.isEmpty())
System.out.println("The stack contains: " + stack.toString());
stack.pop();
System.out.println("poping element 5"+stack.toString());
System.out.println("The size of the stack is: " + stack.size());
System.out.println("pushing 7 element ");
stack.push(7);
System.out.println("Now stack elements");
System.out.println(stack.toString());
System.out.println("pushing 8 element ");
stack.push(8);
System.out.println("Now stack elements");
System.out.println(stack.toString());
if (!stack.isEmpty())
System.out.println("The stack contains: " + stack.toString());
}
/**
* An array implementation of a stack in which the bottom of the stack is
* fixed at index 0.
*
* @author Java Foundations
* @version 4.0
*/
public static class ArrayDropOutStack implements StackADT {
private final static int DEFAULT_CAPACITY = 100;
private int top;
private T[] stack;
/**
* Creates an empty stack using the default capacity.
*/
public ArrayDropOutStack() {
this(DEFAULT_CAPACITY);
}
/**
* Creates an empty stack using the specified capacity.
*
* @param initialCapacity
* the initial size of the array
*/
@SuppressWarnings("unchecked") // see p505.
public ArrayDropOutStack(int initialCapacity) {
top = 0;
stack = (T[]) (new Object[initialCapacity]);
}
/**
* Adds the specified element to the top of this stack, expanding the
* capacity of the array if necessary.
*
* @param element
* generic element to be pushed onto stack
*/
public void push(T element)
{
if(top 0) {
return false;
} else {
return true;
}
}
/**
* Returns the number of elements in this stack.
*
* @return the number of elements in the stack
*/
public int size() {
int total = 0;
for (int i = 0; i < top; i++) {
if (top > 0) {
total++;
}
}
return total;
}
/**
* Returns a string representation of this stack. The string has the
* form of each element printed on its own line, with the top most
* element displayed first, and the bottom most element displayed last.
* If the list is empty, returns the word "empty".
*
* @return a string representation of the stack
*/
public String toString() {
String results = "";
for (int i = size() - 1; i >= 0; i--) {
if (top >= i) {
results += " " + stack[i];
} else {
results = "0";
}
}
return results;
}
}
}
------------------------------------------------------------------------------------------------------------
Sample output:
DROP-OUT STACK TESTING
Stack :
4
3
2
1
pushing 5 element
Now stack elements
5
4
3
2
The size of the stack is: 4
The stack contains:
5
4
3
2
poping element 5
4
3
2
The size of the stack is: 3
pushing 7 element
Now stack elements
7
4
3
2
pushing 8 element
Now stack elements
8
7
4
3
The stack contains:
8
7
4
3
Solution
//Modifications highlighted in bold letters
//DropOutStack.java
import java.util.Arrays;
public class DropOutStack {
/**
* Defines the interface to a stack collection.
*
* @author Java Foundations
* @version 4.0
*/
public interface StackADT {
/**
* Adds the specified element to the top of this stack.
*
* @param element
* element to be pushed onto the stack
*/
public void push(T element);
/**
* Removes and returns the top element from this stack.
*
* @return the element removed from the stack
*/
public T pop();
/**
* Returns without removing the top element of this stack.
*
* @return the element on top of the stack
*/
public T peek();
/**
* Returns true if this stack contains no elements.
*
* @return true if the stack is empty
*/
public boolean isEmpty();
/**
* Returns the number of elements in this stack.
*
* @return the number of elements in the stack
*/
public int size();
/**
* Returns a string representation of this stack.
*
* @return a string representation of the stack
*/
public String toString();
}
/**
* Represents the situation in which a collection is empty.
*
* @author Java Foundations
* @version 4.0
*/
public static class EmptyCollectionException extends RuntimeException {
/**
* Sets up this exception with an appropriate message.
*
* @param collection
* the name of the collection
*/
public EmptyCollectionException(String collection) {
super("The " + collection + " is empty.");
}
}
/**
* Program entry point for stack testing.
*
* @param args
* Argument list.
*/
public static void main(String[] args) {
ArrayDropOutStack stack = new ArrayDropOutStack(4);
System.out.println("DROP-OUT STACK TESTING");
stack.push(1);
stack.push(2);
stack.push(3);
stack.push(4);
System.out.println("Stack : "+stack.toString());
System.out.println("pushing 5 element ");
stack.push(5);
System.out.println("Now stack elements");
System.out.println(stack.toString());
System.out.println("The size of the stack is: " + stack.size());
if (!stack.isEmpty())
System.out.println("The stack contains: " + stack.toString());
stack.pop();
System.out.println("poping element 5"+stack.toString());
System.out.println("The size of the stack is: " + stack.size());
System.out.println("pushing 7 element ");
stack.push(7);
System.out.println("Now stack elements");
System.out.println(stack.toString());
System.out.println("pushing 8 element ");
stack.push(8);
System.out.println("Now stack elements");
System.out.println(stack.toString());
if (!stack.isEmpty())
System.out.println("The stack contains: " + stack.toString());
}
/**
* An array implementation of a stack in which the bottom of the stack is
* fixed at index 0.
*
* @author Java Foundations
* @version 4.0
*/
public static class ArrayDropOutStack implements StackADT {
private final static int DEFAULT_CAPACITY = 100;
private int top;
private T[] stack;
/**
* Creates an empty stack using the default capacity.
*/
public ArrayDropOutStack() {
this(DEFAULT_CAPACITY);
}
/**
* Creates an empty stack using the specified capacity.
*
* @param initialCapacity
* the initial size of the array
*/
@SuppressWarnings("unchecked") // see p505.
public ArrayDropOutStack(int initialCapacity) {
top = 0;
stack = (T[]) (new Object[initialCapacity]);
}
/**
* Adds the specified element to the top of this stack, expanding the
* capacity of the array if necessary.
*
* @param element
* generic element to be pushed onto stack
*/
public void push(T element)
{
if(top 0) {
return false;
} else {
return true;
}
}
/**
* Returns the number of elements in this stack.
*
* @return the number of elements in the stack
*/
public int size() {
int total = 0;
for (int i = 0; i < top; i++) {
if (top > 0) {
total++;
}
}
return total;
}
/**
* Returns a string representation of this stack. The string has the
* form of each element printed on its own line, with the top most
* element displayed first, and the bottom most element displayed last.
* If the list is empty, returns the word "empty".
*
* @return a string representation of the stack
*/
public String toString() {
String results = "";
for (int i = size() - 1; i >= 0; i--) {
if (top >= i) {
results += " " + stack[i];
} else {
results = "0";
}
}
return results;
}
}
}
------------------------------------------------------------------------------------------------------------
Sample output:
DROP-OUT STACK TESTING
Stack :
4
3
2
1
pushing 5 element
Now stack elements
5
4
3
2
The size of the stack is: 4
The stack contains:
5
4
3
2
poping element 5
4
3
2
The size of the stack is: 3
pushing 7 element
Now stack elements
7
4
3
2
pushing 8 element
Now stack elements
8
7
4
3
The stack contains:
8
7
4
3

More Related Content

Similar to Modifications highlighted in bold lettersDropOutStack.javaim.pdf

create a new interface called DropoutStackADT for representing a dro.pdf
create a new interface called DropoutStackADT for representing a dro.pdfcreate a new interface called DropoutStackADT for representing a dro.pdf
create a new interface called DropoutStackADT for representing a dro.pdf
f3apparelsonline
 
So I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfSo I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdf
aksahnan
 
Given the following ADT definition of a stack to use stack .docx
Given the following ADT definition of a stack to use stack .docxGiven the following ADT definition of a stack to use stack .docx
Given the following ADT definition of a stack to use stack .docx
shericehewat
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdf
ARCHANASTOREKOTA
 
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
gudduraza28
 
A linked stack is implemented using a standard Node class as follows.pdf
A linked stack is implemented using a standard Node class as follows.pdfA linked stack is implemented using a standard Node class as follows.pdf
A linked stack is implemented using a standard Node class as follows.pdf
kisgstin23
 
(674335607) cs2309 java-lab-manual
(674335607) cs2309 java-lab-manual(674335607) cs2309 java-lab-manual
(674335607) cs2309 java-lab-manual
Chandrapriya Jayabal
 
EmptyCollectionException-java -- - Represents the situation in which.docx
EmptyCollectionException-java --  - Represents the situation in which.docxEmptyCollectionException-java --  - Represents the situation in which.docx
EmptyCollectionException-java -- - Represents the situation in which.docx
BlakeSGMHemmingss
 
Stack Implementation
Stack ImplementationStack Implementation
Stack Implementation
Zidny Nafan
 
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
 
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
cgraciela1
 
package ADTs public interface CollectionADTltTgt .pdf
package ADTs public interface CollectionADTltTgt      .pdfpackage ADTs public interface CollectionADTltTgt      .pdf
package ADTs public interface CollectionADTltTgt .pdf
syedabdul78662
 
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 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
 
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
 
java question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdfjava question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdf
dbrienmhompsonkath75
 
Here is what I got so far, I dont know how to write union, interse.pdf
Here is what I got so far, I dont know how to write union, interse.pdfHere is what I got so far, I dont know how to write union, interse.pdf
Here is what I got so far, I dont know how to write union, interse.pdf
arihantpatna
 
java write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfjava write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdf
arjuntelecom26
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdf
contact41
 
package com.java2novice.ds.linkedlist;import java.util.NoSuchEleme.pdf
package com.java2novice.ds.linkedlist;import java.util.NoSuchEleme.pdfpackage com.java2novice.ds.linkedlist;import java.util.NoSuchEleme.pdf
package com.java2novice.ds.linkedlist;import java.util.NoSuchEleme.pdf
aptind
 

Similar to Modifications highlighted in bold lettersDropOutStack.javaim.pdf (20)

create a new interface called DropoutStackADT for representing a dro.pdf
create a new interface called DropoutStackADT for representing a dro.pdfcreate a new interface called DropoutStackADT for representing a dro.pdf
create a new interface called DropoutStackADT for representing a dro.pdf
 
So I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfSo I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdf
 
Given the following ADT definition of a stack to use stack .docx
Given the following ADT definition of a stack to use stack .docxGiven the following ADT definition of a stack to use stack .docx
Given the following ADT definition of a stack to use stack .docx
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.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
 
A linked stack is implemented using a standard Node class as follows.pdf
A linked stack is implemented using a standard Node class as follows.pdfA linked stack is implemented using a standard Node class as follows.pdf
A linked stack is implemented using a standard Node class as follows.pdf
 
(674335607) cs2309 java-lab-manual
(674335607) cs2309 java-lab-manual(674335607) cs2309 java-lab-manual
(674335607) cs2309 java-lab-manual
 
EmptyCollectionException-java -- - Represents the situation in which.docx
EmptyCollectionException-java --  - Represents the situation in which.docxEmptyCollectionException-java --  - Represents the situation in which.docx
EmptyCollectionException-java -- - Represents the situation in which.docx
 
Stack Implementation
Stack ImplementationStack Implementation
Stack Implementation
 
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
 
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
 
package ADTs public interface CollectionADTltTgt .pdf
package ADTs public interface CollectionADTltTgt      .pdfpackage ADTs public interface CollectionADTltTgt      .pdf
package ADTs public interface CollectionADTltTgt .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 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
 
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
 
java question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdfjava question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdf
 
Here is what I got so far, I dont know how to write union, interse.pdf
Here is what I got so far, I dont know how to write union, interse.pdfHere is what I got so far, I dont know how to write union, interse.pdf
Here is what I got so far, I dont know how to write union, interse.pdf
 
java write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfjava write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdf
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdf
 
package com.java2novice.ds.linkedlist;import java.util.NoSuchEleme.pdf
package com.java2novice.ds.linkedlist;import java.util.NoSuchEleme.pdfpackage com.java2novice.ds.linkedlist;import java.util.NoSuchEleme.pdf
package com.java2novice.ds.linkedlist;import java.util.NoSuchEleme.pdf
 

More from Lalkamal2

steps are as follows Dissolve the (pressumably.pdf
                     steps are as follows   Dissolve the (pressumably.pdf                     steps are as follows   Dissolve the (pressumably.pdf
steps are as follows Dissolve the (pressumably.pdf
Lalkamal2
 
the two features of the asynchronus connection that allow the receiv.pdf
the two features of the asynchronus connection that allow the receiv.pdfthe two features of the asynchronus connection that allow the receiv.pdf
the two features of the asynchronus connection that allow the receiv.pdf
Lalkamal2
 
Telomerase is the enzyme responsible for maintenance of the length o.pdf
Telomerase is the enzyme responsible for maintenance of the length o.pdfTelomerase is the enzyme responsible for maintenance of the length o.pdf
Telomerase is the enzyme responsible for maintenance of the length o.pdf
Lalkamal2
 
Suppose Bob sends an encrypted document to Alice. To be verifiable, .pdf
Suppose Bob sends an encrypted document to Alice. To be verifiable, .pdfSuppose Bob sends an encrypted document to Alice. To be verifiable, .pdf
Suppose Bob sends an encrypted document to Alice. To be verifiable, .pdf
Lalkamal2
 
probablity = 212 100 = 16.6 Solutionprobablity = 212 10.pdf
probablity = 212  100 = 16.6 Solutionprobablity = 212  10.pdfprobablity = 212  100 = 16.6 Solutionprobablity = 212  10.pdf
probablity = 212 100 = 16.6 Solutionprobablity = 212 10.pdf
Lalkamal2
 
Platinum complexes like Asplastin are powerful antitumor medications.pdf
Platinum complexes like Asplastin are powerful antitumor medications.pdfPlatinum complexes like Asplastin are powerful antitumor medications.pdf
Platinum complexes like Asplastin are powerful antitumor medications.pdf
Lalkamal2
 
Part 1 1)#include stdio.hint testWhileLoop() ; int testFo.pdf
Part 1 1)#include stdio.hint testWhileLoop() ; int testFo.pdfPart 1 1)#include stdio.hint testWhileLoop() ; int testFo.pdf
Part 1 1)#include stdio.hint testWhileLoop() ; int testFo.pdf
Lalkamal2
 
none of them are correct!Solutionnone of them are correct!.pdf
none of them are correct!Solutionnone of them are correct!.pdfnone of them are correct!Solutionnone of them are correct!.pdf
none of them are correct!Solutionnone of them are correct!.pdf
Lalkamal2
 
notor^Solutionnotor^.pdf
notor^Solutionnotor^.pdfnotor^Solutionnotor^.pdf
notor^Solutionnotor^.pdf
Lalkamal2
 
Negative control plate with no DNA transforms competent cells withou.pdf
Negative control plate with no DNA transforms competent cells withou.pdfNegative control plate with no DNA transforms competent cells withou.pdf
Negative control plate with no DNA transforms competent cells withou.pdf
Lalkamal2
 
Message types used by the DHCP boot sequenceop Message type.h.pdf
Message types used by the DHCP boot sequenceop Message type.h.pdfMessage types used by the DHCP boot sequenceop Message type.h.pdf
Message types used by the DHCP boot sequenceop Message type.h.pdf
Lalkamal2
 
Law of conservation of matter(mass)In any closed system subjected .pdf
Law of conservation of matter(mass)In any closed system subjected .pdfLaw of conservation of matter(mass)In any closed system subjected .pdf
Law of conservation of matter(mass)In any closed system subjected .pdf
Lalkamal2
 
It is a unit of measurement for the amount of substance.The mole is .pdf
It is a unit of measurement for the amount of substance.The mole is .pdfIt is a unit of measurement for the amount of substance.The mole is .pdf
It is a unit of measurement for the amount of substance.The mole is .pdf
Lalkamal2
 
In insurance, the term risk pooling refers to the spreading of f.pdf
In insurance, the term risk pooling refers to the spreading of f.pdfIn insurance, the term risk pooling refers to the spreading of f.pdf
In insurance, the term risk pooling refers to the spreading of f.pdf
Lalkamal2
 
Some CO is Added The Pressure of CH4 and H2O will.pdf
                     Some CO is Added The Pressure of CH4 and H2O will.pdf                     Some CO is Added The Pressure of CH4 and H2O will.pdf
Some CO is Added The Pressure of CH4 and H2O will.pdf
Lalkamal2
 
dasSolutiondas.pdf
dasSolutiondas.pdfdasSolutiondas.pdf
dasSolutiondas.pdf
Lalkamal2
 
Comments Figures are not properly numbered. Further signal of figur.pdf
Comments Figures are not properly numbered. Further signal of figur.pdfComments Figures are not properly numbered. Further signal of figur.pdf
Comments Figures are not properly numbered. Further signal of figur.pdf
Lalkamal2
 
Change the value of jug1 and jug 2 accordingly. 1 File WaterJugBSF.j.pdf
Change the value of jug1 and jug 2 accordingly. 1 File WaterJugBSF.j.pdfChange the value of jug1 and jug 2 accordingly. 1 File WaterJugBSF.j.pdf
Change the value of jug1 and jug 2 accordingly. 1 File WaterJugBSF.j.pdf
Lalkamal2
 
Balance sheetBalance sheet is the statement of financial position .pdf
Balance sheetBalance sheet is the statement of financial position .pdfBalance sheetBalance sheet is the statement of financial position .pdf
Balance sheetBalance sheet is the statement of financial position .pdf
Lalkamal2
 
Answer BaSO4K+ is always soluble because it is an alkaline metal..pdf
Answer BaSO4K+ is always soluble because it is an alkaline metal..pdfAnswer BaSO4K+ is always soluble because it is an alkaline metal..pdf
Answer BaSO4K+ is always soluble because it is an alkaline metal..pdf
Lalkamal2
 

More from Lalkamal2 (20)

steps are as follows Dissolve the (pressumably.pdf
                     steps are as follows   Dissolve the (pressumably.pdf                     steps are as follows   Dissolve the (pressumably.pdf
steps are as follows Dissolve the (pressumably.pdf
 
the two features of the asynchronus connection that allow the receiv.pdf
the two features of the asynchronus connection that allow the receiv.pdfthe two features of the asynchronus connection that allow the receiv.pdf
the two features of the asynchronus connection that allow the receiv.pdf
 
Telomerase is the enzyme responsible for maintenance of the length o.pdf
Telomerase is the enzyme responsible for maintenance of the length o.pdfTelomerase is the enzyme responsible for maintenance of the length o.pdf
Telomerase is the enzyme responsible for maintenance of the length o.pdf
 
Suppose Bob sends an encrypted document to Alice. To be verifiable, .pdf
Suppose Bob sends an encrypted document to Alice. To be verifiable, .pdfSuppose Bob sends an encrypted document to Alice. To be verifiable, .pdf
Suppose Bob sends an encrypted document to Alice. To be verifiable, .pdf
 
probablity = 212 100 = 16.6 Solutionprobablity = 212 10.pdf
probablity = 212  100 = 16.6 Solutionprobablity = 212  10.pdfprobablity = 212  100 = 16.6 Solutionprobablity = 212  10.pdf
probablity = 212 100 = 16.6 Solutionprobablity = 212 10.pdf
 
Platinum complexes like Asplastin are powerful antitumor medications.pdf
Platinum complexes like Asplastin are powerful antitumor medications.pdfPlatinum complexes like Asplastin are powerful antitumor medications.pdf
Platinum complexes like Asplastin are powerful antitumor medications.pdf
 
Part 1 1)#include stdio.hint testWhileLoop() ; int testFo.pdf
Part 1 1)#include stdio.hint testWhileLoop() ; int testFo.pdfPart 1 1)#include stdio.hint testWhileLoop() ; int testFo.pdf
Part 1 1)#include stdio.hint testWhileLoop() ; int testFo.pdf
 
none of them are correct!Solutionnone of them are correct!.pdf
none of them are correct!Solutionnone of them are correct!.pdfnone of them are correct!Solutionnone of them are correct!.pdf
none of them are correct!Solutionnone of them are correct!.pdf
 
notor^Solutionnotor^.pdf
notor^Solutionnotor^.pdfnotor^Solutionnotor^.pdf
notor^Solutionnotor^.pdf
 
Negative control plate with no DNA transforms competent cells withou.pdf
Negative control plate with no DNA transforms competent cells withou.pdfNegative control plate with no DNA transforms competent cells withou.pdf
Negative control plate with no DNA transforms competent cells withou.pdf
 
Message types used by the DHCP boot sequenceop Message type.h.pdf
Message types used by the DHCP boot sequenceop Message type.h.pdfMessage types used by the DHCP boot sequenceop Message type.h.pdf
Message types used by the DHCP boot sequenceop Message type.h.pdf
 
Law of conservation of matter(mass)In any closed system subjected .pdf
Law of conservation of matter(mass)In any closed system subjected .pdfLaw of conservation of matter(mass)In any closed system subjected .pdf
Law of conservation of matter(mass)In any closed system subjected .pdf
 
It is a unit of measurement for the amount of substance.The mole is .pdf
It is a unit of measurement for the amount of substance.The mole is .pdfIt is a unit of measurement for the amount of substance.The mole is .pdf
It is a unit of measurement for the amount of substance.The mole is .pdf
 
In insurance, the term risk pooling refers to the spreading of f.pdf
In insurance, the term risk pooling refers to the spreading of f.pdfIn insurance, the term risk pooling refers to the spreading of f.pdf
In insurance, the term risk pooling refers to the spreading of f.pdf
 
Some CO is Added The Pressure of CH4 and H2O will.pdf
                     Some CO is Added The Pressure of CH4 and H2O will.pdf                     Some CO is Added The Pressure of CH4 and H2O will.pdf
Some CO is Added The Pressure of CH4 and H2O will.pdf
 
dasSolutiondas.pdf
dasSolutiondas.pdfdasSolutiondas.pdf
dasSolutiondas.pdf
 
Comments Figures are not properly numbered. Further signal of figur.pdf
Comments Figures are not properly numbered. Further signal of figur.pdfComments Figures are not properly numbered. Further signal of figur.pdf
Comments Figures are not properly numbered. Further signal of figur.pdf
 
Change the value of jug1 and jug 2 accordingly. 1 File WaterJugBSF.j.pdf
Change the value of jug1 and jug 2 accordingly. 1 File WaterJugBSF.j.pdfChange the value of jug1 and jug 2 accordingly. 1 File WaterJugBSF.j.pdf
Change the value of jug1 and jug 2 accordingly. 1 File WaterJugBSF.j.pdf
 
Balance sheetBalance sheet is the statement of financial position .pdf
Balance sheetBalance sheet is the statement of financial position .pdfBalance sheetBalance sheet is the statement of financial position .pdf
Balance sheetBalance sheet is the statement of financial position .pdf
 
Answer BaSO4K+ is always soluble because it is an alkaline metal..pdf
Answer BaSO4K+ is always soluble because it is an alkaline metal..pdfAnswer BaSO4K+ is always soluble because it is an alkaline metal..pdf
Answer BaSO4K+ is always soluble because it is an alkaline metal..pdf
 

Recently uploaded

CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
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
Celine George
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
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
PedroFerreira53928
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
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
Celine George
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 

Recently uploaded (20)

CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
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 libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
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
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
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
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 

Modifications highlighted in bold lettersDropOutStack.javaim.pdf

  • 1. //Modifications highlighted in bold letters //DropOutStack.java import java.util.Arrays; public class DropOutStack { /** * Defines the interface to a stack collection. * * @author Java Foundations * @version 4.0 */ public interface StackADT { /** * Adds the specified element to the top of this stack. * * @param element * element to be pushed onto the stack */ public void push(T element); /** * Removes and returns the top element from this stack. * * @return the element removed from the stack */ public T pop(); /** * Returns without removing the top element of this stack. * * @return the element on top of the stack */ public T peek(); /** * Returns true if this stack contains no elements. * * @return true if the stack is empty */
  • 2. public boolean isEmpty(); /** * Returns the number of elements in this stack. * * @return the number of elements in the stack */ public int size(); /** * Returns a string representation of this stack. * * @return a string representation of the stack */ public String toString(); } /** * Represents the situation in which a collection is empty. * * @author Java Foundations * @version 4.0 */ public static class EmptyCollectionException extends RuntimeException { /** * Sets up this exception with an appropriate message. * * @param collection * the name of the collection */ public EmptyCollectionException(String collection) { super("The " + collection + " is empty."); } } /** * Program entry point for stack testing. * * @param args * Argument list.
  • 3. */ public static void main(String[] args) { ArrayDropOutStack stack = new ArrayDropOutStack(4); System.out.println("DROP-OUT STACK TESTING"); stack.push(1); stack.push(2); stack.push(3); stack.push(4); System.out.println("Stack : "+stack.toString()); System.out.println("pushing 5 element "); stack.push(5); System.out.println("Now stack elements"); System.out.println(stack.toString()); System.out.println("The size of the stack is: " + stack.size()); if (!stack.isEmpty()) System.out.println("The stack contains: " + stack.toString()); stack.pop(); System.out.println("poping element 5"+stack.toString()); System.out.println("The size of the stack is: " + stack.size()); System.out.println("pushing 7 element "); stack.push(7); System.out.println("Now stack elements"); System.out.println(stack.toString()); System.out.println("pushing 8 element "); stack.push(8); System.out.println("Now stack elements"); System.out.println(stack.toString()); if (!stack.isEmpty()) System.out.println("The stack contains: " + stack.toString());
  • 4. } /** * An array implementation of a stack in which the bottom of the stack is * fixed at index 0. * * @author Java Foundations * @version 4.0 */ public static class ArrayDropOutStack implements StackADT { private final static int DEFAULT_CAPACITY = 100; private int top; private T[] stack; /** * Creates an empty stack using the default capacity. */ public ArrayDropOutStack() { this(DEFAULT_CAPACITY); } /** * Creates an empty stack using the specified capacity. * * @param initialCapacity * the initial size of the array */ @SuppressWarnings("unchecked") // see p505. public ArrayDropOutStack(int initialCapacity) { top = 0; stack = (T[]) (new Object[initialCapacity]); } /** * Adds the specified element to the top of this stack, expanding the * capacity of the array if necessary. * * @param element * generic element to be pushed onto stack */
  • 5. public void push(T element) { if(top 0) { return false; } else { return true; } } /** * Returns the number of elements in this stack. * * @return the number of elements in the stack */ public int size() { int total = 0; for (int i = 0; i < top; i++) { if (top > 0) { total++; } } return total; } /** * Returns a string representation of this stack. The string has the * form of each element printed on its own line, with the top most * element displayed first, and the bottom most element displayed last. * If the list is empty, returns the word "empty". * * @return a string representation of the stack */ public String toString() { String results = ""; for (int i = size() - 1; i >= 0; i--) { if (top >= i) { results += " " + stack[i]; } else {
  • 6. results = "0"; } } return results; } } } ------------------------------------------------------------------------------------------------------------ Sample output: DROP-OUT STACK TESTING Stack : 4 3 2 1 pushing 5 element Now stack elements 5 4 3 2 The size of the stack is: 4 The stack contains: 5 4 3 2 poping element 5 4 3 2 The size of the stack is: 3 pushing 7 element Now stack elements 7 4
  • 7. 3 2 pushing 8 element Now stack elements 8 7 4 3 The stack contains: 8 7 4 3 Solution //Modifications highlighted in bold letters //DropOutStack.java import java.util.Arrays; public class DropOutStack { /** * Defines the interface to a stack collection. * * @author Java Foundations * @version 4.0 */ public interface StackADT { /** * Adds the specified element to the top of this stack. * * @param element * element to be pushed onto the stack */ public void push(T element); /** * Removes and returns the top element from this stack.
  • 8. * * @return the element removed from the stack */ public T pop(); /** * Returns without removing the top element of this stack. * * @return the element on top of the stack */ public T peek(); /** * Returns true if this stack contains no elements. * * @return true if the stack is empty */ public boolean isEmpty(); /** * Returns the number of elements in this stack. * * @return the number of elements in the stack */ public int size(); /** * Returns a string representation of this stack. * * @return a string representation of the stack */ public String toString(); } /** * Represents the situation in which a collection is empty. * * @author Java Foundations * @version 4.0 */ public static class EmptyCollectionException extends RuntimeException {
  • 9. /** * Sets up this exception with an appropriate message. * * @param collection * the name of the collection */ public EmptyCollectionException(String collection) { super("The " + collection + " is empty."); } } /** * Program entry point for stack testing. * * @param args * Argument list. */ public static void main(String[] args) { ArrayDropOutStack stack = new ArrayDropOutStack(4); System.out.println("DROP-OUT STACK TESTING"); stack.push(1); stack.push(2); stack.push(3); stack.push(4); System.out.println("Stack : "+stack.toString()); System.out.println("pushing 5 element "); stack.push(5); System.out.println("Now stack elements"); System.out.println(stack.toString()); System.out.println("The size of the stack is: " + stack.size()); if (!stack.isEmpty()) System.out.println("The stack contains: " + stack.toString()); stack.pop(); System.out.println("poping element 5"+stack.toString());
  • 10. System.out.println("The size of the stack is: " + stack.size()); System.out.println("pushing 7 element "); stack.push(7); System.out.println("Now stack elements"); System.out.println(stack.toString()); System.out.println("pushing 8 element "); stack.push(8); System.out.println("Now stack elements"); System.out.println(stack.toString()); if (!stack.isEmpty()) System.out.println("The stack contains: " + stack.toString()); } /** * An array implementation of a stack in which the bottom of the stack is * fixed at index 0. * * @author Java Foundations * @version 4.0 */ public static class ArrayDropOutStack implements StackADT { private final static int DEFAULT_CAPACITY = 100; private int top; private T[] stack; /** * Creates an empty stack using the default capacity. */ public ArrayDropOutStack() { this(DEFAULT_CAPACITY); } /** * Creates an empty stack using the specified capacity. *
  • 11. * @param initialCapacity * the initial size of the array */ @SuppressWarnings("unchecked") // see p505. public ArrayDropOutStack(int initialCapacity) { top = 0; stack = (T[]) (new Object[initialCapacity]); } /** * Adds the specified element to the top of this stack, expanding the * capacity of the array if necessary. * * @param element * generic element to be pushed onto stack */ public void push(T element) { if(top 0) { return false; } else { return true; } } /** * Returns the number of elements in this stack. * * @return the number of elements in the stack */ public int size() { int total = 0; for (int i = 0; i < top; i++) { if (top > 0) { total++; } } return total;
  • 12. } /** * Returns a string representation of this stack. The string has the * form of each element printed on its own line, with the top most * element displayed first, and the bottom most element displayed last. * If the list is empty, returns the word "empty". * * @return a string representation of the stack */ public String toString() { String results = ""; for (int i = size() - 1; i >= 0; i--) { if (top >= i) { results += " " + stack[i]; } else { results = "0"; } } return results; } } } ------------------------------------------------------------------------------------------------------------ Sample output: DROP-OUT STACK TESTING Stack : 4 3 2 1 pushing 5 element Now stack elements 5 4 3 2
  • 13. The size of the stack is: 4 The stack contains: 5 4 3 2 poping element 5 4 3 2 The size of the stack is: 3 pushing 7 element Now stack elements 7 4 3 2 pushing 8 element Now stack elements 8 7 4 3 The stack contains: 8 7 4 3