Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

  7. Use the following code as a base.

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

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();

}

LinearNode Class

package stack;

public final class LinearNode { private T element; private LinearNode next; public LinearNode() { element = null; next = null; } public LinearNode(T element) { this.element = element; next = null; } public void setElement (T element) { this.element = element; } public void setNext(LinearNode node) { next = node; } public T getElement() {return element;} public LinearNode getNext() { return next;} public String toString() { return "" +element; }

} Painting Class:

Objectives:

Successful and correct implementation of the Painting Class

Test all six methods of the Stack implementation: pop, push, isEmpty, toString, size, peek using the two stack of your own classes.

Test all the methods in the Painting class you created yourself through the LinkedStack object.

Implementation of the six methods in the Stack class.

pop, push, isEmpty, size, peek. toString

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced MySQL 8 Discover The Full Potential Of MySQL And Ensure High Performance Of Your Database

Authors: Eric Vanier ,Birju Shah ,Tejaswi Malepati

1st Edition

1788834445, 978-1788834445

More Books

Students also viewed these Databases questions