Question: Complete the implementation of the LinkedStack class by implementing the peek(), isEmpty(), size() and toString() method. Design and create a class named Painting. Test all

  1. Complete the implementation of the LinkedStack class by implementing the peek(), isEmpty(), size() and toString() method.

  2. Design and create a class named Painting.

  3. Test all the methods in the Painting class as well as those in LinkedStack. You must test the Painting methods through objects on the on the Stack, not as an object itself.

  4. Include Javadoc in StackInterface, and generate Javadoc so that you have the doc folder in your project.

  5. Use the logically correct packaging structure to group your classes.

  6. Implement the toString method of StackInterface correctly. When used, it should print out the top element first and the bottom element last. Must test the toString method several times to show that it is not obliterating the stack.

LinkedStack Class

package stack;

import exception.StackException;

public class LinkedStack implements StackInterface { private LinearNode top; private int count; public LinkedStack() { top = null; count = 0; } public LinkedStack(T element) { LinearNode node = new LinearNode(element); top = node; count = 1; }

public void push(T element) { LinearNodenode = new LinearNode(element); // if(count == 0) { // top = node; // } // else { // node.setNext(Top); // top = node; // } if(count != 0) node.setNext(top); top = node; count++; } public T pop()throws StackException{ if (count == 0) throw new StackException(); T temp = top.getElement(); top = top.getNext(); count--; return temp; } public T peek() throws StackException{ public int size() { public boolean isEmpty() { public String toString() { } } } }

StackException Class

package exception;

public class StackException extends RuntimeException { public StackException(){ super("The stack is empty"); } public StackException(String msg) { super(msg); }

}

StackInterface class

package stack;

import exception.StackException;

public interface StackInterface { public void push(T element); public T pop() throws StackException; public T peek() throws StackException; public int size(); public boolean isEmpty(); public String toString();

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!