HW3 Assignment

What to do?

You must turn in your program by Wednesday, October 13th, 2021 at 11:59AM NOON PST.

In this assignment, you are to implement an array-based stack of longs.

The functions to write/complete in LongStack.java:

LongStackEngine (int stackSize, String caller)
void emptyStack ()
Integer getCapacity ()
Integer getOccupancy ()
boolean isEmptyStack ()
boolean isFullStack ()
Long pop ()
boolean push (long item)
Long top ()

Other than what listed above, you should write the function header for the jettisonStackEngine() method in LongStack.java:

Function Descriptions

In this assignment, you are to write function headers for all of the following functions, and file headers for any files you edit.

LongStackEngine:

The constructor of the LongStackEngine object. It should properly initialize every field of a stack engine and track the memory.

Hints: Refer to your notes. Refer to your notes from discussion. If you didn't take notes, ask a classmate to share their notes.
Note that we have handled the memory tracking part for you, so all you need to do is to initialize everything correctly.

emptyStack:

Effectively empties the LongStackEngine of all its elements.

Hints: Don't over think!

getCapacity:

Returns how many elements can the LongStackEngine store.

getOccupancy:

Returns the number of elements in LongStackEngine.

isEmptyStack:

Returns true if LongStackEngine is empty, and false if it is not.

isFullStack:

Returns true if LongStackEngine is full, and false if it is not.

pop:

Removes an item from the top of the LongStackEngine, and sends it back by returning this element. If pop failed, you should return null.

Hint: Do error checking. Make use of your isEmptyStack method.

push:

Adds item to the top of the LongStackEngine. If push failed, you should return false.

Hint: Do your error checking. Make use of your isFullStack method. The value of the stack element at the stackPointer tells you what the last occupied space in the LongStackEngine is, so use that. Don't forget to change the value of the LongStackEngine element at the stackPointer after the item has been pushed onto the LongStackEngine.

top:

Sends back the item on the top of the LongStackEngine through returning this element. If top failed, you should return null.

Hint: Do your error checkings. This method is similar to pop. You'll want to use the stackPointer.

Implementation Restrictions

To implement these functions, you may not make calls to ANY functions you did not author except for

System.out.*
System.err.*

Grading breakdown

Commenting/Documentation:
27.5%
Correctness/Execution:
45%
Style:
27.5%

How to get started?

Copy and past the following commands into your terminal

cd
cd ../public/hw3
make install
cd
cd hw3/java
mv LongStack.java.empty LongStack.java
ls