Create a method called public static boolean solved(StackAsMyArrayListbottles[])  which checks if the game is solved

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Create a method called public static boolean solved(StackAsMyArrayListbottles[])  which checks if the game is solved

食 l &
Vo) 4G
12:56 O 3 O
Q No internet connection
efundi.nwu.ac.za/access/conte
4
public class StackAsMyArrayList<E>
{
MyArrayList<E> theStack;
public StackAsMyArrayList()
theStack = new MyArrayList<E>();
}
public void push(E newElement) //insert at
end of array!
{
if (!theStack.checkSpace(O)
throw new
IndexOutOfBoundsException
("Stack out of bounds");
theStack.add(theStack.getSize(),newElement);
public E pop() //remove end of array
{
E temp
= null;
boolean isDone = false;
if (theStack.getSize() > 0)
temp=theStack.remove(theStack.getSize()-1);
return temp; // temp will be
null in special case of empty list
}
public String toString()
{
return theStack.toString();
}
}//end class
+
...
Transcribed Image Text:食 l & Vo) 4G 12:56 O 3 O Q No internet connection efundi.nwu.ac.za/access/conte 4 public class StackAsMyArrayList<E> { MyArrayList<E> theStack; public StackAsMyArrayList() theStack = new MyArrayList<E>(); } public void push(E newElement) //insert at end of array! { if (!theStack.checkSpace(O) throw new IndexOutOfBoundsException ("Stack out of bounds"); theStack.add(theStack.getSize(),newElement); public E pop() //remove end of array { E temp = null; boolean isDone = false; if (theStack.getSize() > 0) temp=theStack.remove(theStack.getSize()-1); return temp; // temp will be null in special case of empty list } public String toString() { return theStack.toString(); } }//end class + ...
食 l &
Vo) 4G
12:56 P O ?/
Q No internet connection
efundi.nwu.ac.za/access/conte
4
public class MyArrayList<E>
{
private int size; // Number of elements in
the list
private E[] data;
private int MAXELEMENTS = 100;
/** Create an empty list */
public MyArrayList() {
data =
(E[])new
Object[MAXELEMENTS];// cannot create array of
generics
size = 0; // Number of elements in the
list
}
public int getMAXELEMENTS(){
return MAXELEMENTS;
}
public boolean checkSpace()
{
if (size+1<MAXELEMENTS)
return true;
else
return false;
public void add(int index, E e) {
// Ensure the index is in the right range
if (index < 0 || index > size)
throw new IndexOut0fBoundsException
("Index: " + index + ", Size: " +
size);
// Move the elements to the right after the
specified index
for (int i = size
data[i + 1] = data[i];
// Insert new element to data[index]
data[index]
// Increase size by 1
1; i >= index; i--)
= e;
+
Transcribed Image Text:食 l & Vo) 4G 12:56 P O ?/ Q No internet connection efundi.nwu.ac.za/access/conte 4 public class MyArrayList<E> { private int size; // Number of elements in the list private E[] data; private int MAXELEMENTS = 100; /** Create an empty list */ public MyArrayList() { data = (E[])new Object[MAXELEMENTS];// cannot create array of generics size = 0; // Number of elements in the list } public int getMAXELEMENTS(){ return MAXELEMENTS; } public boolean checkSpace() { if (size+1<MAXELEMENTS) return true; else return false; public void add(int index, E e) { // Ensure the index is in the right range if (index < 0 || index > size) throw new IndexOut0fBoundsException ("Index: " + index + ", Size: " + size); // Move the elements to the right after the specified index for (int i = size data[i + 1] = data[i]; // Insert new element to data[index] data[index] // Increase size by 1 1; i >= index; i--) = e; +
Expert Solution
steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY