SlideShare ist ein Scribd-Unternehmen logo
1 von 16
Downloaden Sie, um offline zu lesen
So I have this code( StackInAllSocks ) and I implemented the method but I can't seem to figure
out why there isn't anything showing up on the console. It should pop,peek and push b using the
methods from the class called ArrayListTen . The ArrayListTen works fine and compiles the
tested code of Rigth# but for StackInAllSocks it doesn't complete at all. note that file
VodeDodeis not to be changed is just a Node storage area of the array list.
Did I implement the method on StackInAllSocks correctly? if so, should I not use the method
from the ArrayListTen .?
__________________________________________________________________________
: the code is : VodeDodeis
class VodeDode<T> {
private T data;
private VodeDode<T> next;
private VodeDode<T> prev;
public VodeDode(T data) {
this.data = data;
this.next = null;
this.prev = null;}
public T getData() {
return data;}
public void setData(T data) {
this.data = data;}
public VodeDode<T> getNext() {
return this.next;}
public void setNext(VodeDode<T> next) {
this.next = next;}
public VodeDode<T> getPrev() {
return this.prev;}
public void setPrev(VodeDode<T> prev) {
this.prev = prev;}
@Override
public String toString() {
return data.toString();}}
_________________________________________________________________________
CODE that works fine called ArrayListTen:
import java.util.Iterator;
public class ArrayListTen<T> implements Iterable<T> {
private VodeDode<T> head; //beginning of list
private VodeDode<T> tail; //end of list
private int size;
private VodeDode<T> new_item;
public ArrayListTen( ){
this.head = null;
this.tail = null;
this.size = 0;}
public int lenght() {
return size ;}
public T getBegin() {
if (this.head != null) {
return head.getData();}
else { return null;}}
public void addBegin(T value) {
VodeDode<T> newVodeDode =new VodeDode<T>(value);
if (this.head== null) {
head = newVodeDode;
tail =newVodeDode;}
else {VodeDode<T> temp = head;
head = newVodeDode;
head.setNext(temp);}
size++;}
public T removeBegin() {
if(this.head == null) {
return null;}
else {T current = head.getData();
if (tail == head) {
tail = null;
head = null;
} else {
head = head.getNext();
head.setPrev(null);}size--;
return current;}}
public T getEnd() {
if (tail != null) {
return tail.getData();
} else {
return null;}}
public void addEnd(T value) {
VodeDode<T> newVodeDode = new VodeDode<T>(value);
if (this.tail == null) {
head = newVodeDode;
tail = newVodeDode;
} else {
newVodeDode.setPrev(tail);
tail.setNext(newVodeDode);
tail = newVodeDode;}
size++;}
public T removeEnd() {
if(this.tail == null) {
return null;}
else {
T current = tail.getData();//was head.
if (head == tail) {
head = null;
tail = null;
} else {
tail = tail.getPrev();
tail.setNext(null);}
size--;
return current;}}
public T removeBN(T value) {
VodeDode<T> currVodeDode = head;
VodeDode<T> prevVodeDode = null;
while(currVodeDode != null){
if(currVodeDode.getData().equals(value)){
if(prevVodeDode != null){
prevVodeDode.setNext(currVodeDode.getNext());}
else{
head = currVodeDode.getNext();}
return currVodeDode.getData();}
prevVodeDode = currVodeDode;
currVodeDode = currVodeDode.getNext();
}return null ;}
public String listToString(int start) {
if (start < 0 || start >= size()) {
return "";}
StringBuilder s = new StringBuilder(size());
Node<T> current = head;
for (int i = 0; i < start; i++) {
current = current.getNext();}
while (current != null) {
s.append(current.getData()).append(" ");
current = current.getNext();}
return s.toString();
}public String listToStringBackward() {
String result = "";
if (head == null) {
return result;
}VodeDode<T> current = head;
while (current != null) {
result = current.getData() + " " + result;
current = current.getNext();
}return result;
} public Iterator<T> iterator() {
return new Iterator<T>() {
VodeDode<T> current = head;
public boolean hasNext() {
return current != null;
}public T next() {
if (current == null) {
throw new NullPointerException();
}T data = current.getData();
current = current.getNext();
return data;}};}
public Iterator<T> backwardIterator() {
return new Iterator<T>() {
VodeDode<T> current = tail;
public boolean hasNext() {
return current != null;
}
public T next() {
if (current == null) {
throw new NullPointerException();
}
T data = current.getData();
current = current.getPrev();
return data;
}
};
}
//******************************************************
//******* BELOW THIS LINE IS PROVIDED code *******
//******* Do NOT edit code! *******
//******* Remember to add JavaDoc *******
//******************************************************
// return a string representing all values in the list, from beginning to end,
// seperated by a single space
// return empty string for an empty list
// O(n) where n is the number of items
// This would work if your listToString(index) works
public String listToString() {
return listToString(0);
}//******************************************************
//******* BELOW THIS LINE IS TESTING CODE *******
//******* Edit it as much as you'd like! *******
//******* Remember to add JavaDoc *******
//******************************************************
public static void main(String[] args) {
ArrayListTen<Integer> list = new ArrayListTen<>();
list.addBegin(122);
list.addBegin(345);
list.addBegin(389);
list.addBegin(999);
System.out.println(list.listToString());
//System.out.println(list.listToStringBackward());
//System.out.println(list.listToString());
if (list.getBegin()==999 && list.getEnd()==122 &&
list.listToString().equals("122 345 389 999 ")) {
System.out.println("Rigth1");}
//addEnd
list.addEnd(333);
if (list.listToString().equals("122 345 389 999 333 ")) {
System.out.println("Rigth2");}
ArrayListTen<String> states = new ArrayListTen<>();
states.addEnd("A");
states.addEnd("B");
states.addEnd("C");
states.addEnd("D");
states.addEnd("E");
//removeBNBegin, removeBNEnd
String name1 = states.removeBegin();
String name2 = states.removeEnd();
if (name1.equals("A") && name2.equals("E") &&
states.listToString().equals("B C D ") &&
states.listToStringBackward().equals("D C B ")){
System.out.println("Rigth3");}
//System.out.println(states.listToString());
//System.out.println(states.listToStringBackward());
//System.out.println(name1);
//System.out.println(name2);
//removeBN
ArrayListTen<Integer> nums = new ArrayListTen<>();
nums.addEnd(10);
nums.addEnd(20);
nums.addEnd(10);
nums.addEnd(30);
nums.addEnd(10);
nums.addEnd(40);
if (nums.removeBN(10)==10 && nums.listToString().equals("20 10 30 10 40 ")
&& nums.removeBN(10)==10 && nums.listToString().equals("20 30 10 40 ")
&& nums.removeBN(50)==null && nums.removeBN(40)==40
&& nums.listToString().equals("20 30 10 ")
&& nums.listToStringBackward().equals("10 30 20 ")){
System.out.println("Rigth4");}
int total = 0;
for (Integer num: nums){
total += num;
}if (total == 60){
System.out.println("Rigth5");
}Iterator<String> iter = states.iterator();
if (iter.hasNext() && iter.next().equals("MD") &&
iter.next().equals("NJ") && iter.next().equals("WV")
&& !iter.hasNext()){
System.out.println("Rigth6");
}
//remove special case
class SomeType{
private String value;
public SomeType(String value) { this.value = value; }
public boolean equals(Object o) {
if (!(o instanceof SomeType)) return false;
//both null
if (((SomeType)o).value == null && this.value==null) return true;
//both empty string
if (((SomeType)o).value.length() == 0 && this.value.length()==0) return true;
//compare only the leading chars
return ((SomeType)o).value.charAt(0) == this.value.charAt(0);}
public String toString(){ return value;}}
SomeType item1 = new SomeType("Apple");
SomeType item2 = new SomeType("Alli");
SomeType item3 = new SomeType("Be");
SomeType item4 = new SomeType("der");
ArrayListTen<SomeType> items = new ArrayListTen<>();
items.addEnd(item1);
items.addEnd(item2);
items.addEnd(item3);
SomeType deleted = items.removeBN(item4);
if (deleted.toString().equals("Apple")){
System.out.println("Rigth7");
}}}
_______________________________________________________________________
The code below is the one that doesn't let me compile anything at all or pass these tests of
printing Right# CODE: StackInAllSocks
import java.util.Iterator;
public class StackInAllSocks<T> implements Iterable<T> {
// storage - you MUST use this for credit!
// Do NOT change the name or type
// NOTE: you cannot use any arrays or JCF instances in your implementation.
private ArrayListTen<T> EE;
// ADD MORE PRIVATE MEMBERS HERE IF NEEDED!
// private int size;
// initialize the StackInAllSocks to being an empty StackInAllSocks
public StackInAllSocks() {
EE = new ArrayListTen<>();
size = 0;}
public void push(T item) {
// push an item onto the StackInAllSocks
// you may assume the item is not null
EE.addBegin(item);
size++;}
public T pop() {
// pop an item off the StackInAllSocks
// if there are no items on the StackInAllSocks, return null
if (isEmpty()) {
return null;}
size--;
return EE.removeEnd();
}
public T peek() {
// return the top of the StackInAllSocks (but don't remove it)
// if there are no items on the StackInAllSocks, return null
if (isEmpty()) {
return null;
}
return EE.getBegin();
}
public String toString() {
// Create a string of the StackInAllSocks where each item
// is separated by a space from bottom to top, that is:
// - the bottom of the StackInAllSocks should be shown to the left; and
// - the top of the StackInAllSocks should be shown to the right
// Hint: Reuse the provided code from another class
// instead of writing this yourself!
// O(n) where n is the number of items in stack
StringBuilder sb = new StringBuilder(); for (T item : EE) {
sb.append(item).append(" ");}return sb.toString().trim();}
public boolean isEmpty() {
// return whether or not the StackInAllSocks is empty
// O(1)
return EE != null;
}
public StackInAllSocks<T> reverseStack() {
// return a new stack with all items from this stack
// but in the reverse order
// i.e. current stack top should be at the bottom of the reversed stack
// current stack bottom should be at the top of the reversed stack
// Note: the returned new stack should not be affected by any
// subsequent operations of this stack. See examples below in main().
// O(n) where n is the number of items in stack
StackInAllSocks<T> reversedStack = new StackInAllSocks<>();
for (T item : EE) {
reversedStack.push(item);}
return reversedStack; }
public Iterator<T> iterator() {
return EE.iterator();}
//******************************************************
//******* BELOW THIS LINE IS TESTING CODE *******
//******* Edit it as much as you'd like! *******
//******* Remember to add JavaDoc *******
//******************************************************
public static void main(String[] args) {
StackInAllSocks<String> s = new StackInAllSocks<>();
s.push("student");
//s.push("----------->");
s.push("help");
s.peek();
if (!s.isEmpty() && s.peek().equals("help") && s.pop().equals("help")
&& s.peek().equals("student")) {
System.out.println("Right1");}
System.out.println(s);
System.out.println(s.isEmpty());
System.out.println(s.peek().equals("help"));
//System.out.println(s.pop());
s.push("support");
s.push("and");
s.push("advocacy");
s.push("center");
if (s.toString().equals("student support and advocacy center")
&& !s.isEmpty()) {
System.out.println("Right2");
}
//System.out.println(s);
StackInAllSocks<String> back = s.reverseStack();
s.pop();
s.pop();
s.pop();
//System.out.println(s);
if (s.toString().equals("student support") && s.pop().equals("support")
&& s.pop().equals("student") && s.isEmpty() && s.pop() == null
&& back.toString().equals("center advocacy and support student")) {
System.out.println("Right3");}}}
Thank you For looking at my code

Weitere ähnliche Inhalte

Ähnlich wie So I have this code(StackInAllSocks) and I implemented the method but.pdf

import java-util--- public class MyLinkedList{ public static void.pdf
import java-util---  public class MyLinkedList{    public static void.pdfimport java-util---  public class MyLinkedList{    public static void.pdf
import java-util--- public class MyLinkedList{ public static void.pdfasarudheen07
 
package singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfpackage singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfamazing2001
 
Implement the ADT stack by using an array stack to contain its entri.pdf
Implement the ADT stack by using an array stack to contain its entri.pdfImplement the ADT stack by using an array stack to contain its entri.pdf
Implement the ADT stack by using an array stack to contain its entri.pdfSIGMATAX1
 
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
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfravikapoorindia
 
Stack Implementation
Stack ImplementationStack Implementation
Stack ImplementationZidny Nafan
 
Java Generics
Java GenericsJava Generics
Java Genericsjeslie
 
03.DS_Store__MACOSX03._.DS_Store03A2.DS_Store__.docx
03.DS_Store__MACOSX03._.DS_Store03A2.DS_Store__.docx03.DS_Store__MACOSX03._.DS_Store03A2.DS_Store__.docx
03.DS_Store__MACOSX03._.DS_Store03A2.DS_Store__.docxhoney725342
 
Implementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdfImplementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdfmaheshkumar12354
 
1 The goal is to implement DataStructuresArrayStack accor.pdf
1 The goal is to implement DataStructuresArrayStack accor.pdf1 The goal is to implement DataStructuresArrayStack accor.pdf
1 The goal is to implement DataStructuresArrayStack accor.pdfsaradashata
 
I need help in writing the test cases of the below methods i.pdf
I need help in writing the test cases of the below methods i.pdfI need help in writing the test cases of the below methods i.pdf
I need help in writing the test cases of the below methods i.pdfadianantsolutions
 
can you add a delete button and a add button to the below program. j.pdf
can you add a delete button and a add button to the below program. j.pdfcan you add a delete button and a add button to the below program. j.pdf
can you add a delete button and a add button to the below program. j.pdfsales88
 
4. The size of instructions can be fixed or variable. What are advant.pdf
4. The size of instructions can be fixed or variable. What are advant.pdf4. The size of instructions can be fixed or variable. What are advant.pdf
4. The size of instructions can be fixed or variable. What are advant.pdfmumnesh
 
Help please!!(Include your modified DList.java source code file in.pdf
Help please!!(Include your modified DList.java source code file in.pdfHelp please!!(Include your modified DList.java source code file in.pdf
Help please!!(Include your modified DList.java source code file in.pdfjyothimuppasani1
 
Given the code below create a method called, getCollisionCount that .pdf
Given the code below create a method called, getCollisionCount that .pdfGiven the code below create a method called, getCollisionCount that .pdf
Given the code below create a method called, getCollisionCount that .pdfaucmistry
 
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxNew folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxcurwenmichaela
 
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdfJAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdffantasiatheoutofthef
 
I have created a class hasdhedDictionary that implements the Diction.pdf
I have created a class hasdhedDictionary that implements the Diction.pdfI have created a class hasdhedDictionary that implements the Diction.pdf
I have created a class hasdhedDictionary that implements the Diction.pdfallystraders
 
using the code below write the public V add(K key, V value); that ad.pdf
using the code below write the public V add(K key, V value); that ad.pdfusing the code below write the public V add(K key, V value); that ad.pdf
using the code below write the public V add(K key, V value); that ad.pdfamirthagiftsmadurai
 

Ähnlich wie So I have this code(StackInAllSocks) and I implemented the method but.pdf (20)

import java-util--- public class MyLinkedList{ public static void.pdf
import java-util---  public class MyLinkedList{    public static void.pdfimport java-util---  public class MyLinkedList{    public static void.pdf
import java-util--- public class MyLinkedList{ public static void.pdf
 
package singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfpackage singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdf
 
Implement the ADT stack by using an array stack to contain its entri.pdf
Implement the ADT stack by using an array stack to contain its entri.pdfImplement the ADT stack by using an array stack to contain its entri.pdf
Implement the ADT stack by using an array stack to contain its entri.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
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdf
 
Stack Implementation
Stack ImplementationStack Implementation
Stack Implementation
 
Java Generics
Java GenericsJava Generics
Java Generics
 
03.DS_Store__MACOSX03._.DS_Store03A2.DS_Store__.docx
03.DS_Store__MACOSX03._.DS_Store03A2.DS_Store__.docx03.DS_Store__MACOSX03._.DS_Store03A2.DS_Store__.docx
03.DS_Store__MACOSX03._.DS_Store03A2.DS_Store__.docx
 
Implementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdfImplementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdf
 
1 The goal is to implement DataStructuresArrayStack accor.pdf
1 The goal is to implement DataStructuresArrayStack accor.pdf1 The goal is to implement DataStructuresArrayStack accor.pdf
1 The goal is to implement DataStructuresArrayStack accor.pdf
 
I need help in writing the test cases of the below methods i.pdf
I need help in writing the test cases of the below methods i.pdfI need help in writing the test cases of the below methods i.pdf
I need help in writing the test cases of the below methods i.pdf
 
can you add a delete button and a add button to the below program. j.pdf
can you add a delete button and a add button to the below program. j.pdfcan you add a delete button and a add button to the below program. j.pdf
can you add a delete button and a add button to the below program. j.pdf
 
4. The size of instructions can be fixed or variable. What are advant.pdf
4. The size of instructions can be fixed or variable. What are advant.pdf4. The size of instructions can be fixed or variable. What are advant.pdf
4. The size of instructions can be fixed or variable. What are advant.pdf
 
Help please!!(Include your modified DList.java source code file in.pdf
Help please!!(Include your modified DList.java source code file in.pdfHelp please!!(Include your modified DList.java source code file in.pdf
Help please!!(Include your modified DList.java source code file in.pdf
 
PathOfMostResistance
PathOfMostResistancePathOfMostResistance
PathOfMostResistance
 
Given the code below create a method called, getCollisionCount that .pdf
Given the code below create a method called, getCollisionCount that .pdfGiven the code below create a method called, getCollisionCount that .pdf
Given the code below create a method called, getCollisionCount that .pdf
 
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxNew folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
 
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdfJAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
 
I have created a class hasdhedDictionary that implements the Diction.pdf
I have created a class hasdhedDictionary that implements the Diction.pdfI have created a class hasdhedDictionary that implements the Diction.pdf
I have created a class hasdhedDictionary that implements the Diction.pdf
 
using the code below write the public V add(K key, V value); that ad.pdf
using the code below write the public V add(K key, V value); that ad.pdfusing the code below write the public V add(K key, V value); that ad.pdf
using the code below write the public V add(K key, V value); that ad.pdf
 

Mehr von aksahnan

Skills drill 4-2 word Building- 72 Unit II Overview of the Human Bod.pdf
Skills drill 4-2 word Building-   72 Unit II Overview of the Human Bod.pdfSkills drill 4-2 word Building-   72 Unit II Overview of the Human Bod.pdf
Skills drill 4-2 word Building- 72 Unit II Overview of the Human Bod.pdfaksahnan
 
Sketch the region corresponding to the statement P(z-2-6) Left of a va.pdf
Sketch the region corresponding to the statement P(z-2-6) Left of a va.pdfSketch the region corresponding to the statement P(z-2-6) Left of a va.pdf
Sketch the region corresponding to the statement P(z-2-6) Left of a va.pdfaksahnan
 
Sixty-year-old Philip has been having difficulty catching his breath f.pdf
Sixty-year-old Philip has been having difficulty catching his breath f.pdfSixty-year-old Philip has been having difficulty catching his breath f.pdf
Sixty-year-old Philip has been having difficulty catching his breath f.pdfaksahnan
 
Skeletal System- The Appendicular Skeleton and Joints- Complete skill.pdf
Skeletal System- The Appendicular Skeleton and Joints- Complete skill.pdfSkeletal System- The Appendicular Skeleton and Joints- Complete skill.pdf
Skeletal System- The Appendicular Skeleton and Joints- Complete skill.pdfaksahnan
 
Sketch the region corresponding to the statement P(z-1-5) Shade v Left.pdf
Sketch the region corresponding to the statement P(z-1-5) Shade v Left.pdfSketch the region corresponding to the statement P(z-1-5) Shade v Left.pdf
Sketch the region corresponding to the statement P(z-1-5) Shade v Left.pdfaksahnan
 
Size of Pl- bits Size of P2 - bits Size of Offset - bits.pdf
Size of Pl- bits Size of P2 - bits Size of Offset - bits.pdfSize of Pl- bits Size of P2 - bits Size of Offset - bits.pdf
Size of Pl- bits Size of P2 - bits Size of Offset - bits.pdfaksahnan
 
Sketch each object- Label and indicate the total magnification- Things.pdf
Sketch each object- Label and indicate the total magnification- Things.pdfSketch each object- Label and indicate the total magnification- Things.pdf
Sketch each object- Label and indicate the total magnification- Things.pdfaksahnan
 
Simple GUI using Swing Recreate the GUI using the Swing package (25 po.pdf
Simple GUI using Swing Recreate the GUI using the Swing package (25 po.pdfSimple GUI using Swing Recreate the GUI using the Swing package (25 po.pdf
Simple GUI using Swing Recreate the GUI using the Swing package (25 po.pdfaksahnan
 
sin(4) in tili 10 sie 30.pdf
sin(4) in tili 10 sie 30.pdfsin(4) in tili 10 sie 30.pdf
sin(4) in tili 10 sie 30.pdfaksahnan
 
Simulate on a vertical time axis (with events labeled with the senders.pdf
Simulate on a vertical time axis (with events labeled with the senders.pdfSimulate on a vertical time axis (with events labeled with the senders.pdf
Simulate on a vertical time axis (with events labeled with the senders.pdfaksahnan
 
Singay Copportion hes recorded the following costs for tho vi 101- Toa.pdf
Singay Copportion hes recorded the following costs for tho vi 101- Toa.pdfSingay Copportion hes recorded the following costs for tho vi 101- Toa.pdf
Singay Copportion hes recorded the following costs for tho vi 101- Toa.pdfaksahnan
 
Since the cell making cortisol has a high concentration of cortisol co.pdf
Since the cell making cortisol has a high concentration of cortisol co.pdfSince the cell making cortisol has a high concentration of cortisol co.pdf
Since the cell making cortisol has a high concentration of cortisol co.pdfaksahnan
 
sinckA A nak-ereme inreiter atoud cheose kince it offere.pdf
sinckA A nak-ereme inreiter atoud cheose  kince it offere.pdfsinckA A nak-ereme inreiter atoud cheose  kince it offere.pdf
sinckA A nak-ereme inreiter atoud cheose kince it offere.pdfaksahnan
 
Since dinosaur cannot swim- explain how a fossil can be found on all c.pdf
Since dinosaur cannot swim- explain how a fossil can be found on all c.pdfSince dinosaur cannot swim- explain how a fossil can be found on all c.pdf
Since dinosaur cannot swim- explain how a fossil can be found on all c.pdfaksahnan
 
Simulate the SOP expression- f(W-X-Y-Z)-m(1-2-4-5-6-9-12-14).pdf
Simulate the SOP expression- f(W-X-Y-Z)-m(1-2-4-5-6-9-12-14).pdfSimulate the SOP expression- f(W-X-Y-Z)-m(1-2-4-5-6-9-12-14).pdf
Simulate the SOP expression- f(W-X-Y-Z)-m(1-2-4-5-6-9-12-14).pdfaksahnan
 
SIMs media is specially designed to detect three distinct metabolic pr.pdf
SIMs media is specially designed to detect three distinct metabolic pr.pdfSIMs media is specially designed to detect three distinct metabolic pr.pdf
SIMs media is specially designed to detect three distinct metabolic pr.pdfaksahnan
 
Simulate differential equation dt2d2y-12dtdy5y Simulate the SIR model.pdf
Simulate differential equation dt2d2y-12dtdy5y Simulate the SIR model.pdfSimulate differential equation dt2d2y-12dtdy5y Simulate the SIR model.pdf
Simulate differential equation dt2d2y-12dtdy5y Simulate the SIR model.pdfaksahnan
 
Simple Stains are an indirect staining process most widely used differ.pdf
Simple Stains are an indirect staining process most widely used differ.pdfSimple Stains are an indirect staining process most widely used differ.pdf
Simple Stains are an indirect staining process most widely used differ.pdfaksahnan
 
Situation of facts- Management of conflict situations in the labor are.pdf
Situation of facts- Management of conflict situations in the labor are.pdfSituation of facts- Management of conflict situations in the labor are.pdf
Situation of facts- Management of conflict situations in the labor are.pdfaksahnan
 
Sigma factors recognize the Pribnow Box and the consensus sequence in.pdf
Sigma factors recognize the Pribnow Box and the consensus sequence in.pdfSigma factors recognize the Pribnow Box and the consensus sequence in.pdf
Sigma factors recognize the Pribnow Box and the consensus sequence in.pdfaksahnan
 

Mehr von aksahnan (20)

Skills drill 4-2 word Building- 72 Unit II Overview of the Human Bod.pdf
Skills drill 4-2 word Building-   72 Unit II Overview of the Human Bod.pdfSkills drill 4-2 word Building-   72 Unit II Overview of the Human Bod.pdf
Skills drill 4-2 word Building- 72 Unit II Overview of the Human Bod.pdf
 
Sketch the region corresponding to the statement P(z-2-6) Left of a va.pdf
Sketch the region corresponding to the statement P(z-2-6) Left of a va.pdfSketch the region corresponding to the statement P(z-2-6) Left of a va.pdf
Sketch the region corresponding to the statement P(z-2-6) Left of a va.pdf
 
Sixty-year-old Philip has been having difficulty catching his breath f.pdf
Sixty-year-old Philip has been having difficulty catching his breath f.pdfSixty-year-old Philip has been having difficulty catching his breath f.pdf
Sixty-year-old Philip has been having difficulty catching his breath f.pdf
 
Skeletal System- The Appendicular Skeleton and Joints- Complete skill.pdf
Skeletal System- The Appendicular Skeleton and Joints- Complete skill.pdfSkeletal System- The Appendicular Skeleton and Joints- Complete skill.pdf
Skeletal System- The Appendicular Skeleton and Joints- Complete skill.pdf
 
Sketch the region corresponding to the statement P(z-1-5) Shade v Left.pdf
Sketch the region corresponding to the statement P(z-1-5) Shade v Left.pdfSketch the region corresponding to the statement P(z-1-5) Shade v Left.pdf
Sketch the region corresponding to the statement P(z-1-5) Shade v Left.pdf
 
Size of Pl- bits Size of P2 - bits Size of Offset - bits.pdf
Size of Pl- bits Size of P2 - bits Size of Offset - bits.pdfSize of Pl- bits Size of P2 - bits Size of Offset - bits.pdf
Size of Pl- bits Size of P2 - bits Size of Offset - bits.pdf
 
Sketch each object- Label and indicate the total magnification- Things.pdf
Sketch each object- Label and indicate the total magnification- Things.pdfSketch each object- Label and indicate the total magnification- Things.pdf
Sketch each object- Label and indicate the total magnification- Things.pdf
 
Simple GUI using Swing Recreate the GUI using the Swing package (25 po.pdf
Simple GUI using Swing Recreate the GUI using the Swing package (25 po.pdfSimple GUI using Swing Recreate the GUI using the Swing package (25 po.pdf
Simple GUI using Swing Recreate the GUI using the Swing package (25 po.pdf
 
sin(4) in tili 10 sie 30.pdf
sin(4) in tili 10 sie 30.pdfsin(4) in tili 10 sie 30.pdf
sin(4) in tili 10 sie 30.pdf
 
Simulate on a vertical time axis (with events labeled with the senders.pdf
Simulate on a vertical time axis (with events labeled with the senders.pdfSimulate on a vertical time axis (with events labeled with the senders.pdf
Simulate on a vertical time axis (with events labeled with the senders.pdf
 
Singay Copportion hes recorded the following costs for tho vi 101- Toa.pdf
Singay Copportion hes recorded the following costs for tho vi 101- Toa.pdfSingay Copportion hes recorded the following costs for tho vi 101- Toa.pdf
Singay Copportion hes recorded the following costs for tho vi 101- Toa.pdf
 
Since the cell making cortisol has a high concentration of cortisol co.pdf
Since the cell making cortisol has a high concentration of cortisol co.pdfSince the cell making cortisol has a high concentration of cortisol co.pdf
Since the cell making cortisol has a high concentration of cortisol co.pdf
 
sinckA A nak-ereme inreiter atoud cheose kince it offere.pdf
sinckA A nak-ereme inreiter atoud cheose  kince it offere.pdfsinckA A nak-ereme inreiter atoud cheose  kince it offere.pdf
sinckA A nak-ereme inreiter atoud cheose kince it offere.pdf
 
Since dinosaur cannot swim- explain how a fossil can be found on all c.pdf
Since dinosaur cannot swim- explain how a fossil can be found on all c.pdfSince dinosaur cannot swim- explain how a fossil can be found on all c.pdf
Since dinosaur cannot swim- explain how a fossil can be found on all c.pdf
 
Simulate the SOP expression- f(W-X-Y-Z)-m(1-2-4-5-6-9-12-14).pdf
Simulate the SOP expression- f(W-X-Y-Z)-m(1-2-4-5-6-9-12-14).pdfSimulate the SOP expression- f(W-X-Y-Z)-m(1-2-4-5-6-9-12-14).pdf
Simulate the SOP expression- f(W-X-Y-Z)-m(1-2-4-5-6-9-12-14).pdf
 
SIMs media is specially designed to detect three distinct metabolic pr.pdf
SIMs media is specially designed to detect three distinct metabolic pr.pdfSIMs media is specially designed to detect three distinct metabolic pr.pdf
SIMs media is specially designed to detect three distinct metabolic pr.pdf
 
Simulate differential equation dt2d2y-12dtdy5y Simulate the SIR model.pdf
Simulate differential equation dt2d2y-12dtdy5y Simulate the SIR model.pdfSimulate differential equation dt2d2y-12dtdy5y Simulate the SIR model.pdf
Simulate differential equation dt2d2y-12dtdy5y Simulate the SIR model.pdf
 
Simple Stains are an indirect staining process most widely used differ.pdf
Simple Stains are an indirect staining process most widely used differ.pdfSimple Stains are an indirect staining process most widely used differ.pdf
Simple Stains are an indirect staining process most widely used differ.pdf
 
Situation of facts- Management of conflict situations in the labor are.pdf
Situation of facts- Management of conflict situations in the labor are.pdfSituation of facts- Management of conflict situations in the labor are.pdf
Situation of facts- Management of conflict situations in the labor are.pdf
 
Sigma factors recognize the Pribnow Box and the consensus sequence in.pdf
Sigma factors recognize the Pribnow Box and the consensus sequence in.pdfSigma factors recognize the Pribnow Box and the consensus sequence in.pdf
Sigma factors recognize the Pribnow Box and the consensus sequence in.pdf
 

Kürzlich hochgeladen

Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIShubhangi Sonawane
 
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
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
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
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
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
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
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
 

Kürzlich hochgeladen (20)

Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
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 ...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
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
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
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
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
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
 

So I have this code(StackInAllSocks) and I implemented the method but.pdf

  • 1. So I have this code( StackInAllSocks ) and I implemented the method but I can't seem to figure out why there isn't anything showing up on the console. It should pop,peek and push b using the methods from the class called ArrayListTen . The ArrayListTen works fine and compiles the tested code of Rigth# but for StackInAllSocks it doesn't complete at all. note that file VodeDodeis not to be changed is just a Node storage area of the array list. Did I implement the method on StackInAllSocks correctly? if so, should I not use the method from the ArrayListTen .? __________________________________________________________________________ : the code is : VodeDodeis class VodeDode<T> { private T data; private VodeDode<T> next; private VodeDode<T> prev; public VodeDode(T data) { this.data = data; this.next = null; this.prev = null;} public T getData() { return data;} public void setData(T data) { this.data = data;} public VodeDode<T> getNext() { return this.next;} public void setNext(VodeDode<T> next) { this.next = next;} public VodeDode<T> getPrev() {
  • 2. return this.prev;} public void setPrev(VodeDode<T> prev) { this.prev = prev;} @Override public String toString() { return data.toString();}} _________________________________________________________________________ CODE that works fine called ArrayListTen: import java.util.Iterator; public class ArrayListTen<T> implements Iterable<T> { private VodeDode<T> head; //beginning of list private VodeDode<T> tail; //end of list private int size; private VodeDode<T> new_item; public ArrayListTen( ){ this.head = null; this.tail = null; this.size = 0;} public int lenght() { return size ;} public T getBegin() { if (this.head != null) { return head.getData();}
  • 3. else { return null;}} public void addBegin(T value) { VodeDode<T> newVodeDode =new VodeDode<T>(value); if (this.head== null) { head = newVodeDode; tail =newVodeDode;} else {VodeDode<T> temp = head; head = newVodeDode; head.setNext(temp);} size++;} public T removeBegin() { if(this.head == null) { return null;} else {T current = head.getData(); if (tail == head) { tail = null; head = null; } else { head = head.getNext(); head.setPrev(null);}size--; return current;}} public T getEnd() { if (tail != null) {
  • 4. return tail.getData(); } else { return null;}} public void addEnd(T value) { VodeDode<T> newVodeDode = new VodeDode<T>(value); if (this.tail == null) { head = newVodeDode; tail = newVodeDode; } else { newVodeDode.setPrev(tail); tail.setNext(newVodeDode); tail = newVodeDode;} size++;} public T removeEnd() { if(this.tail == null) { return null;} else { T current = tail.getData();//was head. if (head == tail) { head = null; tail = null; } else { tail = tail.getPrev();
  • 5. tail.setNext(null);} size--; return current;}} public T removeBN(T value) { VodeDode<T> currVodeDode = head; VodeDode<T> prevVodeDode = null; while(currVodeDode != null){ if(currVodeDode.getData().equals(value)){ if(prevVodeDode != null){ prevVodeDode.setNext(currVodeDode.getNext());} else{ head = currVodeDode.getNext();} return currVodeDode.getData();} prevVodeDode = currVodeDode; currVodeDode = currVodeDode.getNext(); }return null ;} public String listToString(int start) { if (start < 0 || start >= size()) { return "";} StringBuilder s = new StringBuilder(size()); Node<T> current = head; for (int i = 0; i < start; i++) { current = current.getNext();}
  • 6. while (current != null) { s.append(current.getData()).append(" "); current = current.getNext();} return s.toString(); }public String listToStringBackward() { String result = ""; if (head == null) { return result; }VodeDode<T> current = head; while (current != null) { result = current.getData() + " " + result; current = current.getNext(); }return result; } public Iterator<T> iterator() { return new Iterator<T>() { VodeDode<T> current = head; public boolean hasNext() { return current != null; }public T next() { if (current == null) { throw new NullPointerException(); }T data = current.getData(); current = current.getNext();
  • 7. return data;}};} public Iterator<T> backwardIterator() { return new Iterator<T>() { VodeDode<T> current = tail; public boolean hasNext() { return current != null; } public T next() { if (current == null) { throw new NullPointerException(); } T data = current.getData(); current = current.getPrev(); return data; } }; } //****************************************************** //******* BELOW THIS LINE IS PROVIDED code ******* //******* Do NOT edit code! ******* //******* Remember to add JavaDoc ******* //****************************************************** // return a string representing all values in the list, from beginning to end,
  • 8. // seperated by a single space // return empty string for an empty list // O(n) where n is the number of items // This would work if your listToString(index) works public String listToString() { return listToString(0); }//****************************************************** //******* BELOW THIS LINE IS TESTING CODE ******* //******* Edit it as much as you'd like! ******* //******* Remember to add JavaDoc ******* //****************************************************** public static void main(String[] args) { ArrayListTen<Integer> list = new ArrayListTen<>(); list.addBegin(122); list.addBegin(345); list.addBegin(389); list.addBegin(999); System.out.println(list.listToString()); //System.out.println(list.listToStringBackward()); //System.out.println(list.listToString()); if (list.getBegin()==999 && list.getEnd()==122 && list.listToString().equals("122 345 389 999 ")) { System.out.println("Rigth1");}
  • 9. //addEnd list.addEnd(333); if (list.listToString().equals("122 345 389 999 333 ")) { System.out.println("Rigth2");} ArrayListTen<String> states = new ArrayListTen<>(); states.addEnd("A"); states.addEnd("B"); states.addEnd("C"); states.addEnd("D"); states.addEnd("E"); //removeBNBegin, removeBNEnd String name1 = states.removeBegin(); String name2 = states.removeEnd(); if (name1.equals("A") && name2.equals("E") && states.listToString().equals("B C D ") && states.listToStringBackward().equals("D C B ")){ System.out.println("Rigth3");} //System.out.println(states.listToString()); //System.out.println(states.listToStringBackward()); //System.out.println(name1); //System.out.println(name2); //removeBN ArrayListTen<Integer> nums = new ArrayListTen<>();
  • 10. nums.addEnd(10); nums.addEnd(20); nums.addEnd(10); nums.addEnd(30); nums.addEnd(10); nums.addEnd(40); if (nums.removeBN(10)==10 && nums.listToString().equals("20 10 30 10 40 ") && nums.removeBN(10)==10 && nums.listToString().equals("20 30 10 40 ") && nums.removeBN(50)==null && nums.removeBN(40)==40 && nums.listToString().equals("20 30 10 ") && nums.listToStringBackward().equals("10 30 20 ")){ System.out.println("Rigth4");} int total = 0; for (Integer num: nums){ total += num; }if (total == 60){ System.out.println("Rigth5"); }Iterator<String> iter = states.iterator(); if (iter.hasNext() && iter.next().equals("MD") && iter.next().equals("NJ") && iter.next().equals("WV") && !iter.hasNext()){ System.out.println("Rigth6"); }
  • 11. //remove special case class SomeType{ private String value; public SomeType(String value) { this.value = value; } public boolean equals(Object o) { if (!(o instanceof SomeType)) return false; //both null if (((SomeType)o).value == null && this.value==null) return true; //both empty string if (((SomeType)o).value.length() == 0 && this.value.length()==0) return true; //compare only the leading chars return ((SomeType)o).value.charAt(0) == this.value.charAt(0);} public String toString(){ return value;}} SomeType item1 = new SomeType("Apple"); SomeType item2 = new SomeType("Alli"); SomeType item3 = new SomeType("Be"); SomeType item4 = new SomeType("der"); ArrayListTen<SomeType> items = new ArrayListTen<>(); items.addEnd(item1); items.addEnd(item2); items.addEnd(item3); SomeType deleted = items.removeBN(item4); if (deleted.toString().equals("Apple")){
  • 12. System.out.println("Rigth7"); }}} _______________________________________________________________________ The code below is the one that doesn't let me compile anything at all or pass these tests of printing Right# CODE: StackInAllSocks import java.util.Iterator; public class StackInAllSocks<T> implements Iterable<T> { // storage - you MUST use this for credit! // Do NOT change the name or type // NOTE: you cannot use any arrays or JCF instances in your implementation. private ArrayListTen<T> EE; // ADD MORE PRIVATE MEMBERS HERE IF NEEDED! // private int size; // initialize the StackInAllSocks to being an empty StackInAllSocks public StackInAllSocks() { EE = new ArrayListTen<>(); size = 0;} public void push(T item) { // push an item onto the StackInAllSocks // you may assume the item is not null EE.addBegin(item); size++;} public T pop() { // pop an item off the StackInAllSocks
  • 13. // if there are no items on the StackInAllSocks, return null if (isEmpty()) { return null;} size--; return EE.removeEnd(); } public T peek() { // return the top of the StackInAllSocks (but don't remove it) // if there are no items on the StackInAllSocks, return null if (isEmpty()) { return null; } return EE.getBegin(); } public String toString() { // Create a string of the StackInAllSocks where each item // is separated by a space from bottom to top, that is: // - the bottom of the StackInAllSocks should be shown to the left; and // - the top of the StackInAllSocks should be shown to the right // Hint: Reuse the provided code from another class // instead of writing this yourself! // O(n) where n is the number of items in stack StringBuilder sb = new StringBuilder(); for (T item : EE) {
  • 14. sb.append(item).append(" ");}return sb.toString().trim();} public boolean isEmpty() { // return whether or not the StackInAllSocks is empty // O(1) return EE != null; } public StackInAllSocks<T> reverseStack() { // return a new stack with all items from this stack // but in the reverse order // i.e. current stack top should be at the bottom of the reversed stack // current stack bottom should be at the top of the reversed stack // Note: the returned new stack should not be affected by any // subsequent operations of this stack. See examples below in main(). // O(n) where n is the number of items in stack StackInAllSocks<T> reversedStack = new StackInAllSocks<>(); for (T item : EE) { reversedStack.push(item);} return reversedStack; } public Iterator<T> iterator() { return EE.iterator();} //****************************************************** //******* BELOW THIS LINE IS TESTING CODE ******* //******* Edit it as much as you'd like! *******
  • 15. //******* Remember to add JavaDoc ******* //****************************************************** public static void main(String[] args) { StackInAllSocks<String> s = new StackInAllSocks<>(); s.push("student"); //s.push("----------->"); s.push("help"); s.peek(); if (!s.isEmpty() && s.peek().equals("help") && s.pop().equals("help") && s.peek().equals("student")) { System.out.println("Right1");} System.out.println(s); System.out.println(s.isEmpty()); System.out.println(s.peek().equals("help")); //System.out.println(s.pop()); s.push("support"); s.push("and"); s.push("advocacy"); s.push("center"); if (s.toString().equals("student support and advocacy center") && !s.isEmpty()) { System.out.println("Right2"); }
  • 16. //System.out.println(s); StackInAllSocks<String> back = s.reverseStack(); s.pop(); s.pop(); s.pop(); //System.out.println(s); if (s.toString().equals("student support") && s.pop().equals("support") && s.pop().equals("student") && s.isEmpty() && s.pop() == null && back.toString().equals("center advocacy and support student")) { System.out.println("Right3");}}} Thank you For looking at my code