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!!!
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; i15
elements[i] = input.next();16
switch (which) {17
case 1 : // test empty queue18
System.out.println(q.toString());19
break;20
case 2 : // test insert method21
for(String s : elements)22
q.insert(s);23
System.out.println(q.toString());24
break;25
case 3 : // test remove method26
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 Stackstack1; private Stack
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started