Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone help!!!!!!!!!! MyStack and MyQueue public class CSE205_Assignment03 { public static void main(String[] args) { System.out.println(IStack tests -----------------------------); IStack_ctor_test(); IStack_push1_test(); IStack_push3_test(); IStack_push100_test(); IStack_pop1_test(); IStack_pop3_test();

Can someone help!!!!!!!!!! MyStack and MyQueue

image text in transcribed

image text in transcribed

public class CSE205_Assignment03 { public static void main(String[] args) { System.out.println("IStack tests -----------------------------"); IStack_ctor_test(); IStack_push1_test(); IStack_push3_test(); IStack_push100_test(); IStack_pop1_test(); IStack_pop3_test(); IStack_pop100_test(); IStack_search100_test(); System.out.println("IQueue tests -----------------------------"); IQueue_ctor_test(); IQueue_add1_test(); IQueue_add3_test(); IQueue_add100_test(); IQueue_remove1_test(); IQueue_remove3_test(); IQueue_remove100_test(); IQueue_search100_test(); } public static void IStack_ctor_test() { IStack s = new MyStack(); assertEqual(0, s.size(), "IStack_ctor_test: size", false); assertEqual(true, s.empty(), "IStack_ctor_test: empty", false); } public static void IStack_push1_test() { IStack s = new MyStack(); s.push(1); assertEqual(1, s.size(), "IStack_push1_test: size", false); assertEqual(false, s.empty(), "IStack_push1_test: empty", false); assertEqual(1, (int)s.peek(), "IStack_push1_test: peek", false); } public static void IStack_push3_test() { IStack s = new MyStack(); s.push(1);s.push(2);s.push(3); assertEqual(3, s.size(), "IStack_push3_test: size", false); assertEqual(3, (int)s.peek(), "IStack_push3_test: peek", false); } public static void IStack_push100_test() { IStack s = new MyStack(); for (int i = 0; i  

/** A queue is a first in first out (FIFO) data structure. New items are added to the end of the list. Items are removed from the front of the list. */ public interface IQueue { /** Inserts the specified element at the end of this queue. */ public void add(Object item); /** Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty. @return the first item in this queue or null if the queue is empty */ public Object peek(); /** searches the queue for an item. @return the zero-based index of the item in the queue; returns -1 if the item is not in the queue. */ public int search(Object item); /** Retrieves and removes the head of this queue. @return the first item in the queue */ public Object remove(); /** A count of the number of items in the queue. @return A count of the number of items in the queue. */ public int size(); /** Tests if this queue is empty. @return true if the queue is empty */ public boolean empty(); } 
/** A stack is a last in first out (LIFO) data structure. New items are pushed onto the top of the list. Items are popped from the top of the list. */ public interface IStack { /** Pushes an item onto the top of this stack. */ public void push(Object item); /** Looks at the object at the top of this stack without removing it from the stack. @return the item at the top of the stack or throws a NoSuchElementException is the stack is empty */ public Object peek(); /** searches the stack for an item. @return the zero-based index of the item in the stack; returns -1 if the item is not in the stack. */ public int search(Object item); /** Removes the object at the top of this stack and returns that object as the value of this function. @return the item at the top of the stack or throws a NoSuchElementException is the stack is empty */ public Object pop(); /** A count of the number of items in the stack. @return A count of the number of items in the stack. */ public int size(); /** Tests if this stack is empty. @return true if the stack is empty */ public boolean empty(); } 

import java.util.NoSuchElementException; public class MyQueue implements IQueue { // add any necessary variables here . . ----- @Override public void add(Object item) { } @Override public Object peek() { } @Override public int search(Object item) { } @Override public Object remove() { } @Override public int size() { } @Override public boolean empty() { } // add any necessary methods or classes below . . ----- } 

import java.util.NoSuchElementException; public class MyStack implements IStack { // add any necessary variables here . . ----- @Override public void push(Object item) { } @Override public Object peek() { } @Override public int search(Object item) { } @Override public Object pop() { } @Override public int size() { } @Override public boolean empty() { } // add any necessary methods or classes below . . ----- } 
Assignment Requirements For this assignment you are given the following Java source code files: CSE205_Assignment03.java IStack.java IQueue.java MyStack.java MyQueue.java (This file is complete-you will make no changes to this file) (This file is complete-you will make no changes to this file) (This file is complete you will make no changes to this file) (you must complete this file) (you must complete this file) The specifications for the files are given below (including the UML diagram on the following page) Special requirements You are not allowed to use any of the standard Java collation types (like ArrayList). You may use simple arrays. You may also use any code from your Assignment 02 submission 1. size methoo a. 2. empty method a. 3. peek method a. b. Returns the number of items in the collection. Returns true if the size of the collection is zero; otherwise returns false Returns the item at the front or top of the collection Throws a NoSuchElementException if the collection is empty 4. search method a. Returns the (zero-based) number of elements from the front or top of the collection where the specified item is first found. Returns -1 if the item is not found in the collection MyStack 1. You must implement the IStack interface as either a linked list or an array list (refer to your work from Assignment 02). Your MyStack must not be arbitrarily limited to any fixed size at run-time push method 2. Insert the new item at the top of the stack. a. 3. pop method a. b. Remove and return the item at the top of the stack. Throws a NoSuchElementException if the stack is empty MyQueue 1. You must implement the IQueue interface as either a linked list or an array list (refer to your work from Assignment 02). Your MyQueue must not be arbitrarily limited to any fixed size at run-time 2. add method a. Insert the new item at the back of the queue 3. remove method Remove and return the item at the front of the queue Throws a NoSuchElementException if the queue is empty a. b

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

Students also viewed these Databases questions

Question

1. What are your creative strengths?

Answered: 1 week ago

Question

What metaphors might describe how we work together?

Answered: 1 week ago