Question: Please help for the JAVA code based on the instructions below. Please meet all the requirements and passed all the sample inputs/outputs in the instruction.

Please help for the JAVA code based on the instructions below. Please meet all the requirements and passed all the sample inputs/outputs in the instruction. THANKS!!!

Please help for the JAVA code based on the instructions below. Please

Below is the DriverMain.java code (NO NEED TO WRITE THE CODE HERE)

------------------------------------------------------------------------------------------------------

import java.util.*;

2

import java.lang.*;

3

import java.io.*;

4

5

public class MyQueueDriver {

6

7

 public static void main(String[] args){

8

 MyQueue q = new MyQueue();

9

 Scanner input = new Scanner(System.in);

10

 int which = input.nextInt(); //which test case

11

 int quantity = 0; // number of elements to add in the queue

12

 if(which != 1) quantity = input.nextInt();

13

 String[] elements = new String[quantity];

14

 for(int i = 0; i  

15

 elements[i] = input.next(); 

16

 switch (which) {

17

 case 1 : // test empty queue

18

 System.out.println(q.toString());

19

 break;

20

 case 2 : // test insert method

21

 for(String s : elements)

22

 q.insert(s);

23

 System.out.println(q.toString()); 

24

 break; 

25

 case 3 : // test remove method

26

 for(String s : elements)

27

 q.insert(s);

28

 q.remove();

29

 System.out.println(q.toString());

30

 break;

31

 }

32

 }

33

}

Below is the code that need to be completed (PLEASE WRITE THE CODE HERE. PLEASE WRITE THE CODE TO COMPLETE ALL THE FUNCTIONS AND PASS ALL THE SAMPLE INPUTS)

-------------------------------------------------------------------------------------------------------------

import java.util.*;

import java.lang.*;

import java.io.*;

public class MyQueue{

private int maxCapacity = 4;

private Stack stack1;

private Stack stack2;

public MyQueue(){

}

public int size(){

}

public void insert(String value){

}

public String remove(){

}

private void shiftStacks(){

}

public boolean isEmpty() {

}

public boolean isFull(){

}

@Override //[QueueSize:Full/Empty:QueueElementsList]

public String toString(){

shiftStacks();

StringBuilder sb = new StringBuilder("[");

sb.append(this.size()).append(":");

if(this.isEmpty())

sb.append("Empty").append(":");

else if (this.isFull())

sb.append("Full").append(":");

while(!isEmpty()){

sb.append(this.remove());

if(this.size()!=0) sb.append(", ");

}

sb.append("]");

return sb.toString();

}

}

Implement a MyQuee lass which implements a queue using two stacks private int maxCapacity 4 private Stack stack1; private Stack

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!