SlideShare a Scribd company logo
1 of 9
Need help with writing the test cases for the following code in java.
public class ArrayBasedStack<T> implements StackADT<T> {
private T[] stackArray;
private int size;
private int capacity;
@SuppressWarnings("unchecked")
public ArrayBasedStack(int initialCapacity) {
size = 0;
this.capacity = initialCapacity;
stackArray = (T[])new Object[capacity];
}
public ArrayBasedStack() {
this(100);
}
/**
* Checks if the stack is empty.
*
* @return Returns true if the stack is empty.
*/
@Override
public boolean isEmpty() {
return size == 0;
}
/**
* Checks the item at the top of the
* stack without removing it.
*
* @return Item at the top of the stack.
*/
@Override
public T peek() throws EmptyStackException {
if (isEmpty()) {
throw new EmptyStackException();
}
return stackArray[size - 1];
}
/**
* Removes the item at the top of
* the stack.
*
* @return The item that was removed.
*/
@Override
public T pop() throws EmptyStackException {
if (isEmpty()) {
throw new EmptyStackException();
}
T result = stackArray[size - 1];
stackArray[size - 1] = null;
size--;
return result;
}
/**
* Pushes an item onto the stack.
*
* @param item
* Item to be pushed
* onto the stack.
*/
@Override
public void push(T item) {
if (size == capacity) {
expandCapacity();
}
stackArray[size] = item;
size ++;
}
/**
* Checks if an item is in the stack.
*
* @param item
* Item to be looked for.
* @return Returns true if the item is
* somewhere in the stack.
*/
@Override
public boolean contains(T item) {
for (int i = size - 1; i >= 0; i--) {
if (stackArray[i].equals(item)) {
return true;
}
}
return false;
}
/**
* Number of items in the stack.
*
* @return The number of items in
* the stack.
*/
@Override
public int size() {
return size;
}
/**
* Clears the stack (removes all of
* the items from the stack).
*/
@Override
public void clear() {
for (int i = 0; i < size; i++) {
stackArray[i] = null;
}
size = 0;
}
/**
* Returns an array with a copy of each element in the stack with the top of
* the stack being the last element
*
* @return the array representation of the stack
*/
@Override
public Object[] toArray() {
@SuppressWarnings("unchecked")
T[] copy = (T[])new Object[this.size()];
for (int i = 0; i < this.size(); i++) {
copy[i] = this.stackArray[i];
}
return copy;
}
/**
* Expands the capacity of the stack by doubling its current capacity.
*/
private void expandCapacity() {
@SuppressWarnings("unchecked")
T[] newArray = (T[])new Object[this.capacity * 2];
for (int i = 0; i < this.capacity; i++) {
newArray[i] = this.stackArray[i];
}
this.stackArray = newArray;
this.capacity *= 2;
}
/**
* Returns the string representation of the stack.
*
* [] (if the stack is empty)
* [bottom, item, ..., item, top] (if the stack contains items)
*
* @return the string representation of the stack.
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append('[');
boolean firstItem = true;
for (int i = 0; i < this.size(); i++) {
if (!firstItem) {
builder.append(", ");
}
else {
firstItem = false;
}
// String.valueOf will print null or the toString of the item
builder.append(String.valueOf(this.stackArray[i]));
}
builder.append(']');
return builder.toString();
}
/**
* Two stacks are equal iff they both have the same size and contain the
* same elements in the same order.
*
* @param other
* the other object to compare to this
*
* @return {@code true}, if the stacks are equal; {@code false} otherwise.
*/
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (other == null) {
return false;
}
if (this.getClass().equals(other.getClass())) {
ArrayBasedStack<?> otherStack = (ArrayBasedStack<?>)other;
if (this.size() != otherStack.size()) {
return false;
}
Object[] otherArray = otherStack.toArray();
for (int i = 0; i < this.size(); i++) {
if (!(this.stackArray[i].equals(otherArray[i]))) {
return false;
}
}
return true;
}
return false;
}
}

More Related Content

Similar to Need help with writing the test cases for the following code in java-.docx

Please review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdfPlease review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdffathimafancyjeweller
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfravikapoorindia
 
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.pdfkisgstin23
 
Stack Implementation
Stack ImplementationStack Implementation
Stack ImplementationZidny Nafan
 
(674335607) cs2309 java-lab-manual
(674335607) cs2309 java-lab-manual(674335607) cs2309 java-lab-manual
(674335607) cs2309 java-lab-manualChandrapriya Jayabal
 
package algs13;import stdlib.;import java.util.Iterator;im.docx
package algs13;import  stdlib.;import java.util.Iterator;im.docxpackage algs13;import  stdlib.;import java.util.Iterator;im.docx
package algs13;import stdlib.;import java.util.Iterator;im.docxgerardkortney
 
Were writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdfWere writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdffsenterprises
 
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.pdfaksahnan
 
1. Suppose you want to implement an ADT in which you can insert valu.pdf
1. Suppose you want to implement an ADT in which you can insert valu.pdf1. Suppose you want to implement an ADT in which you can insert valu.pdf
1. Suppose you want to implement an ADT in which you can insert valu.pdfforwardcom41
 
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.pdff3apparelsonline
 
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.pdfarihantpatna
 
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
 

Similar to Need help with writing the test cases for the following code in java-.docx (20)

Please review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdfPlease review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdf
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.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
 
Stack Implementation
Stack ImplementationStack Implementation
Stack Implementation
 
(674335607) cs2309 java-lab-manual
(674335607) cs2309 java-lab-manual(674335607) cs2309 java-lab-manual
(674335607) cs2309 java-lab-manual
 
package algs13;import stdlib.;import java.util.Iterator;im.docx
package algs13;import  stdlib.;import java.util.Iterator;im.docxpackage algs13;import  stdlib.;import java.util.Iterator;im.docx
package algs13;import stdlib.;import java.util.Iterator;im.docx
 
Were writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdfWere writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.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
 
Posfix
PosfixPosfix
Posfix
 
1. Suppose you want to implement an ADT in which you can insert valu.pdf
1. Suppose you want to implement an ADT in which you can insert valu.pdf1. Suppose you want to implement an ADT in which you can insert valu.pdf
1. Suppose you want to implement an ADT in which you can insert valu.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
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
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 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
 

More from LucasmHKChapmant

Liquidity Risk and Expected Stock Returns Lubos Pastor and Robert F- S.docx
Liquidity Risk and Expected Stock Returns Lubos Pastor and Robert F- S.docxLiquidity Risk and Expected Stock Returns Lubos Pastor and Robert F- S.docx
Liquidity Risk and Expected Stock Returns Lubos Pastor and Robert F- S.docxLucasmHKChapmant
 
Microlensing of a background star by a planet Decreases the brightness.docx
Microlensing of a background star by a planet Decreases the brightness.docxMicrolensing of a background star by a planet Decreases the brightness.docx
Microlensing of a background star by a planet Decreases the brightness.docxLucasmHKChapmant
 
message until the user enters Q- in the format H- Hydrogen- periodic-p.docx
message until the user enters Q- in the format H- Hydrogen- periodic-p.docxmessage until the user enters Q- in the format H- Hydrogen- periodic-p.docx
message until the user enters Q- in the format H- Hydrogen- periodic-p.docxLucasmHKChapmant
 
Measurement of project quality and performance- The most crucial infor.docx
Measurement of project quality and performance- The most crucial infor.docxMeasurement of project quality and performance- The most crucial infor.docx
Measurement of project quality and performance- The most crucial infor.docxLucasmHKChapmant
 
Mechanism Diagrams - Special Senses PrSO-001 5- Vision Note- absence o.docx
Mechanism Diagrams - Special Senses PrSO-001 5- Vision Note- absence o.docxMechanism Diagrams - Special Senses PrSO-001 5- Vision Note- absence o.docx
Mechanism Diagrams - Special Senses PrSO-001 5- Vision Note- absence o.docxLucasmHKChapmant
 
McConnell Corporation has bonds on the market with 12 years to maturit.docx
McConnell Corporation has bonds on the market with 12 years to maturit.docxMcConnell Corporation has bonds on the market with 12 years to maturit.docx
McConnell Corporation has bonds on the market with 12 years to maturit.docxLucasmHKChapmant
 
Match the pattern of change in allele frequencies with the mechanisa b.docx
Match the pattern of change in allele frequencies with the mechanisa b.docxMatch the pattern of change in allele frequencies with the mechanisa b.docx
Match the pattern of change in allele frequencies with the mechanisa b.docxLucasmHKChapmant
 
Match the description to the correct vessel name- the longest vein in.docx
Match the description to the correct vessel name- the longest vein in.docxMatch the description to the correct vessel name- the longest vein in.docx
Match the description to the correct vessel name- the longest vein in.docxLucasmHKChapmant
 
Match the statements with the accounting principles- A partnership cha.docx
Match the statements with the accounting principles- A partnership cha.docxMatch the statements with the accounting principles- A partnership cha.docx
Match the statements with the accounting principles- A partnership cha.docxLucasmHKChapmant
 
Match these cellular network acronyms to their function- IMSI IMEI ICC.docx
Match these cellular network acronyms to their function- IMSI IMEI ICC.docxMatch these cellular network acronyms to their function- IMSI IMEI ICC.docx
Match these cellular network acronyms to their function- IMSI IMEI ICC.docxLucasmHKChapmant
 
Match the best answer on the right to the item on the left- Discrete v.docx
Match the best answer on the right to the item on the left- Discrete v.docxMatch the best answer on the right to the item on the left- Discrete v.docx
Match the best answer on the right to the item on the left- Discrete v.docxLucasmHKChapmant
 
Match the law wht theet Hunction or pupose- A Aederal law far health c.docx
Match the law wht theet Hunction or pupose- A Aederal law far health c.docxMatch the law wht theet Hunction or pupose- A Aederal law far health c.docx
Match the law wht theet Hunction or pupose- A Aederal law far health c.docxLucasmHKChapmant
 
Match the following terms related to soil profiles- The base geologica.docx
Match the following terms related to soil profiles- The base geologica.docxMatch the following terms related to soil profiles- The base geologica.docx
Match the following terms related to soil profiles- The base geologica.docxLucasmHKChapmant
 
Match the scenarios given in the left-hand column with the type of dec (1).docx
Match the scenarios given in the left-hand column with the type of dec (1).docxMatch the scenarios given in the left-hand column with the type of dec (1).docx
Match the scenarios given in the left-hand column with the type of dec (1).docxLucasmHKChapmant
 
Majority of people engage this region of the brain to understand the e.docx
Majority of people engage this region of the brain to understand the e.docxMajority of people engage this region of the brain to understand the e.docx
Majority of people engage this region of the brain to understand the e.docxLucasmHKChapmant
 
Match the following genera with correct characteristics- aerobic bacte.docx
Match the following genera with correct characteristics- aerobic bacte.docxMatch the following genera with correct characteristics- aerobic bacte.docx
Match the following genera with correct characteristics- aerobic bacte.docxLucasmHKChapmant
 
Match the following terms to their correct descriptions- pop culture c.docx
Match the following terms to their correct descriptions- pop culture c.docxMatch the following terms to their correct descriptions- pop culture c.docx
Match the following terms to their correct descriptions- pop culture c.docxLucasmHKChapmant
 
Match the description or function with the term or concept- a) Allows.docx
Match the description or function with the term or concept- a) Allows.docxMatch the description or function with the term or concept- a) Allows.docx
Match the description or function with the term or concept- a) Allows.docxLucasmHKChapmant
 
Match the following species with correct characteristics (hint- recall.docx
Match the following species with correct characteristics (hint- recall.docxMatch the following species with correct characteristics (hint- recall.docx
Match the following species with correct characteristics (hint- recall.docxLucasmHKChapmant
 
Marco expects his investment returns to be 9-53 percent and inflation.docx
Marco expects his investment returns to be 9-53 percent and inflation.docxMarco expects his investment returns to be 9-53 percent and inflation.docx
Marco expects his investment returns to be 9-53 percent and inflation.docxLucasmHKChapmant
 

More from LucasmHKChapmant (20)

Liquidity Risk and Expected Stock Returns Lubos Pastor and Robert F- S.docx
Liquidity Risk and Expected Stock Returns Lubos Pastor and Robert F- S.docxLiquidity Risk and Expected Stock Returns Lubos Pastor and Robert F- S.docx
Liquidity Risk and Expected Stock Returns Lubos Pastor and Robert F- S.docx
 
Microlensing of a background star by a planet Decreases the brightness.docx
Microlensing of a background star by a planet Decreases the brightness.docxMicrolensing of a background star by a planet Decreases the brightness.docx
Microlensing of a background star by a planet Decreases the brightness.docx
 
message until the user enters Q- in the format H- Hydrogen- periodic-p.docx
message until the user enters Q- in the format H- Hydrogen- periodic-p.docxmessage until the user enters Q- in the format H- Hydrogen- periodic-p.docx
message until the user enters Q- in the format H- Hydrogen- periodic-p.docx
 
Measurement of project quality and performance- The most crucial infor.docx
Measurement of project quality and performance- The most crucial infor.docxMeasurement of project quality and performance- The most crucial infor.docx
Measurement of project quality and performance- The most crucial infor.docx
 
Mechanism Diagrams - Special Senses PrSO-001 5- Vision Note- absence o.docx
Mechanism Diagrams - Special Senses PrSO-001 5- Vision Note- absence o.docxMechanism Diagrams - Special Senses PrSO-001 5- Vision Note- absence o.docx
Mechanism Diagrams - Special Senses PrSO-001 5- Vision Note- absence o.docx
 
McConnell Corporation has bonds on the market with 12 years to maturit.docx
McConnell Corporation has bonds on the market with 12 years to maturit.docxMcConnell Corporation has bonds on the market with 12 years to maturit.docx
McConnell Corporation has bonds on the market with 12 years to maturit.docx
 
Match the pattern of change in allele frequencies with the mechanisa b.docx
Match the pattern of change in allele frequencies with the mechanisa b.docxMatch the pattern of change in allele frequencies with the mechanisa b.docx
Match the pattern of change in allele frequencies with the mechanisa b.docx
 
Match the description to the correct vessel name- the longest vein in.docx
Match the description to the correct vessel name- the longest vein in.docxMatch the description to the correct vessel name- the longest vein in.docx
Match the description to the correct vessel name- the longest vein in.docx
 
Match the statements with the accounting principles- A partnership cha.docx
Match the statements with the accounting principles- A partnership cha.docxMatch the statements with the accounting principles- A partnership cha.docx
Match the statements with the accounting principles- A partnership cha.docx
 
Match these cellular network acronyms to their function- IMSI IMEI ICC.docx
Match these cellular network acronyms to their function- IMSI IMEI ICC.docxMatch these cellular network acronyms to their function- IMSI IMEI ICC.docx
Match these cellular network acronyms to their function- IMSI IMEI ICC.docx
 
Match the best answer on the right to the item on the left- Discrete v.docx
Match the best answer on the right to the item on the left- Discrete v.docxMatch the best answer on the right to the item on the left- Discrete v.docx
Match the best answer on the right to the item on the left- Discrete v.docx
 
Match the law wht theet Hunction or pupose- A Aederal law far health c.docx
Match the law wht theet Hunction or pupose- A Aederal law far health c.docxMatch the law wht theet Hunction or pupose- A Aederal law far health c.docx
Match the law wht theet Hunction or pupose- A Aederal law far health c.docx
 
Match the following terms related to soil profiles- The base geologica.docx
Match the following terms related to soil profiles- The base geologica.docxMatch the following terms related to soil profiles- The base geologica.docx
Match the following terms related to soil profiles- The base geologica.docx
 
Match the scenarios given in the left-hand column with the type of dec (1).docx
Match the scenarios given in the left-hand column with the type of dec (1).docxMatch the scenarios given in the left-hand column with the type of dec (1).docx
Match the scenarios given in the left-hand column with the type of dec (1).docx
 
Majority of people engage this region of the brain to understand the e.docx
Majority of people engage this region of the brain to understand the e.docxMajority of people engage this region of the brain to understand the e.docx
Majority of people engage this region of the brain to understand the e.docx
 
Match the following genera with correct characteristics- aerobic bacte.docx
Match the following genera with correct characteristics- aerobic bacte.docxMatch the following genera with correct characteristics- aerobic bacte.docx
Match the following genera with correct characteristics- aerobic bacte.docx
 
Match the following terms to their correct descriptions- pop culture c.docx
Match the following terms to their correct descriptions- pop culture c.docxMatch the following terms to their correct descriptions- pop culture c.docx
Match the following terms to their correct descriptions- pop culture c.docx
 
Match the description or function with the term or concept- a) Allows.docx
Match the description or function with the term or concept- a) Allows.docxMatch the description or function with the term or concept- a) Allows.docx
Match the description or function with the term or concept- a) Allows.docx
 
Match the following species with correct characteristics (hint- recall.docx
Match the following species with correct characteristics (hint- recall.docxMatch the following species with correct characteristics (hint- recall.docx
Match the following species with correct characteristics (hint- recall.docx
 
Marco expects his investment returns to be 9-53 percent and inflation.docx
Marco expects his investment returns to be 9-53 percent and inflation.docxMarco expects his investment returns to be 9-53 percent and inflation.docx
Marco expects his investment returns to be 9-53 percent and inflation.docx
 

Recently uploaded

Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesShubhangi Sonawane
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxNikitaBankoti2
 

Recently uploaded (20)

Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 

Need help with writing the test cases for the following code in java-.docx

  • 1. Need help with writing the test cases for the following code in java. public class ArrayBasedStack<T> implements StackADT<T> { private T[] stackArray; private int size; private int capacity; @SuppressWarnings("unchecked") public ArrayBasedStack(int initialCapacity) { size = 0; this.capacity = initialCapacity; stackArray = (T[])new Object[capacity]; } public ArrayBasedStack() { this(100); } /** * Checks if the stack is empty. * * @return Returns true if the stack is empty. */ @Override public boolean isEmpty() { return size == 0; }
  • 2. /** * Checks the item at the top of the * stack without removing it. * * @return Item at the top of the stack. */ @Override public T peek() throws EmptyStackException { if (isEmpty()) { throw new EmptyStackException(); } return stackArray[size - 1]; } /** * Removes the item at the top of * the stack. * * @return The item that was removed. */ @Override public T pop() throws EmptyStackException { if (isEmpty()) { throw new EmptyStackException();
  • 3. } T result = stackArray[size - 1]; stackArray[size - 1] = null; size--; return result; } /** * Pushes an item onto the stack. * * @param item * Item to be pushed * onto the stack. */ @Override public void push(T item) { if (size == capacity) { expandCapacity(); } stackArray[size] = item; size ++; } /** * Checks if an item is in the stack.
  • 4. * * @param item * Item to be looked for. * @return Returns true if the item is * somewhere in the stack. */ @Override public boolean contains(T item) { for (int i = size - 1; i >= 0; i--) { if (stackArray[i].equals(item)) { return true; } } return false; } /** * Number of items in the stack. * * @return The number of items in * the stack. */ @Override public int size() {
  • 5. return size; } /** * Clears the stack (removes all of * the items from the stack). */ @Override public void clear() { for (int i = 0; i < size; i++) { stackArray[i] = null; } size = 0; } /** * Returns an array with a copy of each element in the stack with the top of * the stack being the last element * * @return the array representation of the stack */ @Override public Object[] toArray() { @SuppressWarnings("unchecked") T[] copy = (T[])new Object[this.size()];
  • 6. for (int i = 0; i < this.size(); i++) { copy[i] = this.stackArray[i]; } return copy; } /** * Expands the capacity of the stack by doubling its current capacity. */ private void expandCapacity() { @SuppressWarnings("unchecked") T[] newArray = (T[])new Object[this.capacity * 2]; for (int i = 0; i < this.capacity; i++) { newArray[i] = this.stackArray[i]; } this.stackArray = newArray; this.capacity *= 2; } /** * Returns the string representation of the stack. * * [] (if the stack is empty) * [bottom, item, ..., item, top] (if the stack contains items) *
  • 7. * @return the string representation of the stack. */ @Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append('['); boolean firstItem = true; for (int i = 0; i < this.size(); i++) { if (!firstItem) { builder.append(", "); } else { firstItem = false; } // String.valueOf will print null or the toString of the item builder.append(String.valueOf(this.stackArray[i])); } builder.append(']'); return builder.toString(); } /** * Two stacks are equal iff they both have the same size and contain the * same elements in the same order.
  • 8. * * @param other * the other object to compare to this * * @return {@code true}, if the stacks are equal; {@code false} otherwise. */ @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null) { return false; } if (this.getClass().equals(other.getClass())) { ArrayBasedStack<?> otherStack = (ArrayBasedStack<?>)other; if (this.size() != otherStack.size()) { return false; } Object[] otherArray = otherStack.toArray(); for (int i = 0; i < this.size(); i++) { if (!(this.stackArray[i].equals(otherArray[i]))) { return false;