To write a Generic Collection class for Stack, using the generic Node from Lab 5, and test it using a stack of Car, Integer, and String

To write a Generic Collection class for Stack<E>, using the generic Node<E> from Lab 5, and test it using a stack of Car, Integer, and String

Stack<E>

Don't use plagiarized sources. Get Your Custom Essay on
To write a Generic Collection class for Stack, using the generic Node from Lab 5, and test it using a stack of Car, Integer, and String
Just from $8 /Page 0r 300 words
Order Now

For Programming Lab 6, you are to write your own Generic Collection for a Stack that will use your Node<E> from Lab 5

Save your time - order a paper!

Get your paper written from scratch within the tight deadline. Our service is a reliable solution to all your troubles. Place an order on any task and we will take care of it. You won’t have to worry about the quality and deadlines

Order Paper Now

UML for Stack<E>

Stack<E>
– top : Node<E>
– numElements : int
+ Stack( )
+ push( element : E ) : void
+ pop( ) : E
+ size( ) : int

Here is an additional description of what your stack should contain/how it should perform:

private fields:

– top which points to a Node<E>
– numElements an int

a no-arg Constructor:

– sets top to null
– numElements to 0

push(receives element of type E)

– adds a new node to top of stack
– adds 1 to numElements

pop( ) returns a value of type E

– removes node from top of stack
– decrements numElements by 1

– <<unless the stack is empty-throw EmptyStack exception (provided in Canvas)>>

size( ) returns an int

returns value of numElements

Stack<E> (Stack.java):

Item
Comment with name (2 points)
Comment each method / constructor in javadoc format (8 points)
2 private Fields created as requested
-top:Node<E> and – numElements as int (5 points)
No-arg Constructor
initializes top and numElements to 0 (5 points)
push() method

adds element of type E to stack and increases numElements (15 points)

pop() method
removes item from top of stack, decrements numElements, returns value of type E
or throws EmptyStack exception if stack was empty (15 points)
size() method
returns numElements (5 points)
following the naming guidelines for Classes and identifiers (8 points)
proper indenting (methods indented inside class, statements indented inside method, conditionally executed code indented) (8 points)
organization of your Class( instance variables up top / Constructor / setters/getters ) (8 points)
Lab must compile and run in order to receive any credit

In: Computer Science

Looking for a similar assignment? Get help from our qualified experts!

Order Now