Question: Please Complete the Following in its entirety. Implement LinkedStack class by implementing the peek(), isEmpty(), size(), and toString() method . Design and create a class

Please Complete the Following in its entirety.

Implement LinkedStack class by implementing the peek(), isEmpty(), size(), and toString() method.

Design and create a class called Painting.

-artist: String

-genre: String

-era: String

//constructors

//accessors

//mutators

//toString

Test all methods in LinkedStack and Painting class. Must test the Painting methods through the objects on the Stack, not as an object itself.

Use logically correct packaging structure to group classes.

Implement toString method of StackInterface correctly. Meaning, it should print out the top element first and bottom element last. Must also test the toString method more than once to show it does not obliterate stack.

Please Complete the Following in its entirety. Implement LinkedStack class by implementing

Utilize the following code (simply create a new project within eclipse and create the following classes and paste given code below (some of the code given may need to be modified)):

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; }

//complete the following implementations within LinkedClass

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; }

}

StackException

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

}

StackDriver class

package driver; import exception.StackException; import stack. *; public class StackDriver { public static void main(String[] args) { StackInterface strStack = new ArrayStack(); strStack.push("Class beings."); strStack.push("class ends."); strStack.push("C;ass resumed."); strStack.push("Class stopped."); System.out.println(" Testing toString: " +strStack); System.out.println("Testing the size method: There are " + strStack.size()+ "elements on the stack"); System.out.println("Testing the isEmpty method: the stack is empty? " + strStack.isEmpty()); System.out.println(" Popping the top element: "+ strStack.pop().toString()); System.out.println("Peeking at the top element changed to upper case: " + strStack.peek().toUpperCase()); System.out.println("Testing the size method: There are " + strStack.size() + " elements on the stack"); System.out.println("Testing the isEmpty method: the stack is empty? " + strStack.isEmpty()); try { System.out.println(" Testing the peek and substring method: The top element is " + "\"" + strStack.peek().substring(2,4) + "\""); System.out.println("Element popped: " + strStack.pop()); System.out.println("Element popped: " + strStack.pop()); System.out.println("Element popped: " + strStack.pop()); System.out.println("Testing the StackException being thrown and caught: "); System.out.println("Element popped: " + strStack.pop()); }catch (StackException e) { System.out.println(e); } // System.out.println(" Testing the isEmpty method (should be empty): the stack is empty? " + strStack.isEmpty()); } }

Painting class (To do: Test all methods in LinkedStack and Painting class. Must test the Painting methods through the objects on the Stack, not as an object itself).

Objectives:

Successful implementation of Painting Class

Creates a stack object that holds the class objects in Painting Class

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

Tests all the methods in the Painting class through LinkedStack Object

Implements the six methods in the Stack class. (pop, push, isEmpty, size, peek, toString(call toString to each node/each element in each node (Node.getNext())

Please help !

Java Software Structures DESIGNING AND USING DATA STRUCTURES 4TH EDITION Lewis And Chase

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!