CSC 130 Homework 3 Solved

25.00 $ 12.50 $

Category:

Description

In this assignment you’ll get more practice with stacks and queues.  You will also practice testing your code for edge cases.

MyStack.java

Implement a stack using linked lists data structure.  Implement your own linked list.  You cannot use Java’s java.util.LinkedList.

  • pop(): returns and removes the last value on the stack
  • push(String item): Push a given value onto the stack
  • isEmpty(): returns true or false depending on if the stack is empty
  • printStack(): prints the items on the stack to console
  • Handles errors for all possible edge cases (i.e. doesn’t throw an unhandled exception to the user)
  • MyStack(String[] list): constructor which creates the stack with the items in list on the stack. So if list had {“a”, “b”, “c”} the stack would look like: “c” on top of “b” on top of “a.”

 

MyQueue.java

Implement a queue using the MyStack.java implementation as your data structure.  In other words, your instance variable to hold the queue items will be a MyStack class.

  • enqueue(String item): inserts item into the queue
  • dequeue(): returns and deletes the first element in the queue
  • isEmpty(): returns true or false depending on if the queue is empty
  • printQueue(): prints the items in the queue to console
  • MyQueue(String[] list): constructor which creates the queue with the items in list in the queue: So if list had {“a”, “b”, “c”} the queue would look like: “a” first, then “b”, then “c.”

 

MyTest.java

  • You can have other methods in this class but will be graded to have a:
  • Main method which tests every method you implemented above in MyStack and MyQueue.
  • As you test the methods, print to console (1) what you are testing, (2) what value you are expecting, (3) whether your test passed or failed.
  • Test for edge cases and clearly state in your comment/print out which edge case you’re testing.