create an interface in java that contains the following methods: boolean myPush(T element);  // pushes element onto the stack; returns true if element successfully pushed, false otherwise boolean myPop();  // removes the top element of the stack; returns true if element successfully popped, false otherwise T myTop();  // if the stack is not empty returns the top element of the stack, otherwise returns null String toString();  // returns contents of the stack as a single String int size();  // return number of elements in the stack then create java file that Implements your interface that you created as a linked stack, then use the driver shown in screen shot to test. below is the code for the LLNode class  public class LLNode { protected LLNode link; protected T info; public LLNode(T info) { this.info = info; link = null; }   public void setInfo(T info) { this.info = info; } public T getInfo() { return info; } public void setLink(LLNode link) { this.link = link; } public LLNode getLink() { return link; } } program should output  fruits cost = 35

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter4: More Object Concepts
Section: Chapter Questions
Problem 17RQ
icon
Related questions
Question

how to create an interface in java that contains the following methods:

boolean myPush(T element);  // pushes element onto the stack; returns true if element successfully pushed, false otherwise

boolean myPop();  // removes the top element of the stack; returns true if element successfully popped, false otherwise

T myTop();  // if the stack is not empty returns the top element of the stack, otherwise returns null

String toString();  // returns contents of the stack as a single String

int size();  // return number of elements in the stack

then create java file that Implements your interface that you created as a linked stack, then use the driver shown in screen shot to test. below is the code for the LLNode class 

public class LLNode<T> {

protected LLNode<T> link;

protected T info;

public LLNode(T info) {

this.info = info;

link = null;

}

 

public void setInfo(T info) {

this.info = info;

}

public T getInfo() {

return info;

}

public void setLink(LLNode<T> link) {

this.link = link;

}

public LLNode<T> getLink() {

return link;

}

}

program should output 

fruits cost = 35

 
public class driver {
public static void main(String[] args) {
mxLinkedstack<String> a = new mybiakedStack<Stringl);
int n = 0;
if (asizel) == 0)
n += 5;
if (amueush("Apple"))
n += 5;
if (atostring().eaualslenereCase("Apple\n"))
n += 5;
if (asizel) == 1)
n += 5;
if (amxPush("Orange") && asize() :
== 2 &&
atostring()-eaualslgnereCase("Orange \aAReleIn"))
n += 5;
if (amxTe().eaualslenereCasel"Orange"))
n += 5;
while (amxlea()) {
}
if (amxTog() == null)
n += 5;
Sustemeuterintla("fruits cost =" +n);
}
Transcribed Image Text:public class driver { public static void main(String[] args) { mxLinkedstack<String> a = new mybiakedStack<Stringl); int n = 0; if (asizel) == 0) n += 5; if (amueush("Apple")) n += 5; if (atostring().eaualslenereCase("Apple\n")) n += 5; if (asizel) == 1) n += 5; if (amxPush("Orange") && asize() : == 2 && atostring()-eaualslgnereCase("Orange \aAReleIn")) n += 5; if (amxTe().eaualslenereCasel"Orange")) n += 5; while (amxlea()) { } if (amxTog() == null) n += 5; Sustemeuterintla("fruits cost =" +n); }
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Avoiding deadlock
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT