TESTS GIVE ERROR FOR SHRINK AND add remove 100 values ALSO, DO IT BY CHECKING THE MAIN CLASS WITHOUT CHANGING IT

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

WITE JAVA CODE JUST TO THE GIVEN CODE BELOW!

TESTS GIVE ERROR FOR SHRINK AND add remove 100 values

ALSO, DO IT BY CHECKING THE MAIN CLASS WITHOUT CHANGING IT

class Queue<T> {
  private T[] a = (T[]) new Object[1];
  private int N = 0;
  public boolean isEmpty() {
    return N == 0;
  }
  public int size() {
    return N;
  }
  private void resize(int capacity) { 
    T[] temp = (T[]) new Object[capacity];
    for (int i = 0; i < N; i++) {
      temp[i] = a[i];
    }
    a = temp;
  }
 
  public void enqueue(T item) { 
    if (N == a.length) resize(2*a.length);
    a[N++] = item;
  }
  public T dequeue() {  
    T item = a[--N];
    a[N] = null;
    if (N > 0 && N == a.length/4) resize(a.length/2);
    return item;
  }
 
  // this method is for unit testing; don't touch
  public int getArraySize(){    return a.length;  }
}

 

public class Main {

  public static void main(String[] args)  {

    Queue<Integer> myQueue = new Queue<Integer>();

    int i;

    i = 1;

    myQueue.enqueue(i);  System.out.printf("myQueue.enqueue(%d);\n",i);      

    i = 2;

    myQueue.enqueue(i);  System.out.printf("myQueue.enqueue(%d);\n",i);      

    i = 3;

    myQueue.enqueue(i);  System.out.printf("myQueue.enqueue(%d);\n",i);      

    i = 4;

    myQueue.enqueue(i);  System.out.printf("myQueue.enqueue(%d);\n",i);      

    i = 5;

    myQueue.enqueue(i);  System.out.printf("myQueue.enqueue(%d);\n",i);           

    int x = myQueue.dequeue();

    System.out.printf("myQueue.dequeue() gives back %d;\n",x);      

    x = myQueue.dequeue();

    System.out.printf("myQueue.dequeue() gives back %d;\n",x);      

    x = myQueue.dequeue();

    System.out.printf("myQueue.dequeue() gives back %d;\n",x);      

    i = 6;

    myQueue.enqueue(i);  System.out.printf("myQueue.enqueue(%d);\n",i);

    i = 7;

    myQueue.enqueue(i);  System.out.printf("myQueue.enqueue(%d);\n",i);      

    i = 8;

    myQueue.enqueue(i);  System.out.printf("myQueue.enqueue(%d);\n",i);          

    x = myQueue.dequeue();

    System.out.printf("myQueue.dequeue() gives back %d;\n",x);      

    x = myQueue.dequeue();

    System.out.printf("myQueue.dequeue() gives back %d;\n",x);      

    x = myQueue.dequeue();

    System.out.printf("myQueue.dequeue() gives back %d;\n",x);          

    i = 9;

    myQueue.enqueue(i);  System.out.printf("myQueue.enqueue(%d);\n",i);      

    i = 10;

    myQueue.enqueue(i);  System.out.printf("myQueue.enqueue(%d);\n",i);      

    x = myQueue.dequeue();

    System.out.printf("myQueue.dequeue() gives back %d;\n",x);      

    x = myQueue.dequeue();

    System.out.printf("myQueue.dequeue() gives back %d;\n",x);     

    x = myQueue.dequeue();

    System.out.printf("myQueue.dequeue() gives back %d;\n",x);      

    x = myQueue.dequeue();

    System.out.printf("myQueue.dequeue() gives back %d;\n",x);      

 

    

  }

}

Q Search
Course: Data Structures...
✓ Files
Config files
.replit
Main.java
.settings
.classpath
.project
Main.class
Queue.class
Queue.java
+ maulit siv
✓ Tools
Instructions
<>
Threads
CPU
DI
Debugger
Ā
Queue with an Array-kivanc120200133
cmpe-211020202
Docs
0
RAM
Packages
Shell
+
? Help
⠀
0 Y
Chat
Try Ghostwriter Free
Storage
Git
>_
Console
(6) Shell Sıralması (Shell...
X
Main.java x +
7
8
Main.java
1 public class Main {
2▼ public static void main(String[] args) {
3
4
5
6
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
int i;
1;
i =
Queue<Integer> myQueue = new Queue<Integer>();
i = 2;
i
myQueue.enqueue(i); System.out.printf("myQueue.enqueue (%d); \n",i);
=
i = 4;
i
myQueue.enqueue(i); System.out.printf("myQueue.enqueue (%d);\n", i);
3;
=
myQueue.enqueue(i); System.out.printf("myQueue.enqueue (%d); \n",i);
b Answered: WRITE JAVA...
myQueue.enqueue(i); System.out.printf("myQueue.enqueue (%d);\n", i);
5;
int x =
X = myQueue.dequeue();
i
replit.com
G chegg Write a generic Q...
myQueue.dequeue();
System.out.printf("myQueue.dequeue () gives back %d;\n",x);
25
Line 48: Col 2
myQueue.enqueue(i); System.out.printf("myQueue.enqueue(%d);\n", i);
X = myQueue.dequeue();
i = 6;
Run
System.out.printf("myQueue.dequeue
() gives back %d;\n",x);
System.out.printf("myQueue.dequeue () gives back %d;\n",x);
=
[
1;
i 8;
=
C Home | Chegg.com
myQueue.enqueue(i); System.out.printf("myQueue.enqueue (%d); \n", i);
myQueue.enqueue(i);
System.out.printf("myQueue.enqueue(%d); \n", i);
History
Tests x
Shell x
Resizable Array Impleme...
Chat
Instructions x
Test2
Message: Failed to shrink
Stack Trace:
Main.java - Queue with a...
✓ Submit Q
> Console x +
invoke(NativeMethodAccessorImpl.java:77)
java.lang. AssertionError: expected:<0> but was:<99>
at org.junit.Assert.fail(Assert.java:88)
at org.junit.Assert.failNotEquals(Assert.java:834)
at org.junit. Assert.assertEquals(Assert.java:645)
at org.junit. Assert.assertEquals(Assert.java:631)
at _test_runnerTestSuite. Test2(_test_runnerTestSuite.java:2
5)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.
invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.
at java.base/jdk.internal.reflect.DelegatingMethodAccessorI
at java.base/java.lang.reflect.Method.invoke(Method.java:56
8)
at org.junit.runners.model. FrameworkMethod$1.runReflectiveC
:
mpl.invoke(DelegatingMethodAccessorImpl.java:43)
all(FrameworkMethod.java:50)
ReflectiveCallable.java:12)
y (FrameworkMethod.java:47)
at org.junit.internal.runners.statements. InvokeMethod. evalu
ate (InvokeMethod.java:17)
at org.junit.runners. ParentRunner.runLeaf (ParentRunner.java
:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild (BlockJ
Unit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild (BlockJ
Unit4ClassRunner.java:57)
at org.junit.runners. ParentRunner $3.run(ParentRunner.java:2
90)
at org.junit.runners. ParentRunner$1.schedule(ParentRunner.j
ava:71)
at org.junit.runners. ParentRunner.runChildren (ParentRunner.
java:288)
at org.junit.runners. ParentRunner.access$000(ParentRunner.j
ava:58)
at org.junit.runners.ParentRunner $2.evaluate(ParentRunner.j
ava: 268)
at org.junit.runners. ParentRunner.run(ParentRunner.java:363
at org.junit.internal.runners.model.ReflectiveCallable.run(
at org.junit.runners.model. FrameworkMethod.invokeExplosivel
Transcribed Image Text:Q Search Course: Data Structures... ✓ Files Config files .replit Main.java .settings .classpath .project Main.class Queue.class Queue.java + maulit siv ✓ Tools Instructions <> Threads CPU DI Debugger Ā Queue with an Array-kivanc120200133 cmpe-211020202 Docs 0 RAM Packages Shell + ? Help ⠀ 0 Y Chat Try Ghostwriter Free Storage Git >_ Console (6) Shell Sıralması (Shell... X Main.java x + 7 8 Main.java 1 public class Main { 2▼ public static void main(String[] args) { 3 4 5 6 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 int i; 1; i = Queue<Integer> myQueue = new Queue<Integer>(); i = 2; i myQueue.enqueue(i); System.out.printf("myQueue.enqueue (%d); \n",i); = i = 4; i myQueue.enqueue(i); System.out.printf("myQueue.enqueue (%d);\n", i); 3; = myQueue.enqueue(i); System.out.printf("myQueue.enqueue (%d); \n",i); b Answered: WRITE JAVA... myQueue.enqueue(i); System.out.printf("myQueue.enqueue (%d);\n", i); 5; int x = X = myQueue.dequeue(); i replit.com G chegg Write a generic Q... myQueue.dequeue(); System.out.printf("myQueue.dequeue () gives back %d;\n",x); 25 Line 48: Col 2 myQueue.enqueue(i); System.out.printf("myQueue.enqueue(%d);\n", i); X = myQueue.dequeue(); i = 6; Run System.out.printf("myQueue.dequeue () gives back %d;\n",x); System.out.printf("myQueue.dequeue () gives back %d;\n",x); = [ 1; i 8; = C Home | Chegg.com myQueue.enqueue(i); System.out.printf("myQueue.enqueue (%d); \n", i); myQueue.enqueue(i); System.out.printf("myQueue.enqueue(%d); \n", i); History Tests x Shell x Resizable Array Impleme... Chat Instructions x Test2 Message: Failed to shrink Stack Trace: Main.java - Queue with a... ✓ Submit Q > Console x + invoke(NativeMethodAccessorImpl.java:77) java.lang. AssertionError: expected:<0> but was:<99> at org.junit.Assert.fail(Assert.java:88) at org.junit.Assert.failNotEquals(Assert.java:834) at org.junit. Assert.assertEquals(Assert.java:645) at org.junit. Assert.assertEquals(Assert.java:631) at _test_runnerTestSuite. Test2(_test_runnerTestSuite.java:2 5) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl. invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl. at java.base/jdk.internal.reflect.DelegatingMethodAccessorI at java.base/java.lang.reflect.Method.invoke(Method.java:56 8) at org.junit.runners.model. FrameworkMethod$1.runReflectiveC : mpl.invoke(DelegatingMethodAccessorImpl.java:43) all(FrameworkMethod.java:50) ReflectiveCallable.java:12) y (FrameworkMethod.java:47) at org.junit.internal.runners.statements. InvokeMethod. evalu ate (InvokeMethod.java:17) at org.junit.runners. ParentRunner.runLeaf (ParentRunner.java :325) at org.junit.runners.BlockJUnit4ClassRunner.runChild (BlockJ Unit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild (BlockJ Unit4ClassRunner.java:57) at org.junit.runners. ParentRunner $3.run(ParentRunner.java:2 90) at org.junit.runners. ParentRunner$1.schedule(ParentRunner.j ava:71) at org.junit.runners. ParentRunner.runChildren (ParentRunner. java:288) at org.junit.runners. ParentRunner.access$000(ParentRunner.j ava:58) at org.junit.runners.ParentRunner $2.evaluate(ParentRunner.j ava: 268) at org.junit.runners. ParentRunner.run(ParentRunner.java:363 at org.junit.internal.runners.model.ReflectiveCallable.run( at org.junit.runners.model. FrameworkMethod.invokeExplosivel
Q Search
Course: Data Structures...
✓ Files
Config files
.replit
Main.java
.settings
.classpath
.project
Main.class
Queue.class
Queue.java
+ maulit siv
✓ Tools
Instructions
<>
Threads
CPU
DI
Debugger
Ā
Queue with an Array-kivanc120200133
cmpe-211020202
Docs
0
RAM
Packages
Shell
+
? Help
⠀
0 Y
Chat
Try Ghostwriter Free
Storage
Git
>_
Console
(6) Shell Sıralması (Shell...
X
Main.java x +
7
8
Main.java
1 public class Main {
2▼ public static void main(String[] args) {
3
4
5
6
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
int i;
1;
i =
Queue<Integer> myQueue = new Queue<Integer>();
i = 2;
i
myQueue.enqueue(i); System.out.printf("myQueue.enqueue (%d); \n",i);
=
i = 4;
i
myQueue.enqueue(i); System.out.printf("myQueue.enqueue (%d);\n", i);
3;
=
myQueue.enqueue(i); System.out.printf("myQueue.enqueue (%d); \n",i);
b Answered: WRITE JAVA...
myQueue.enqueue(i); System.out.printf("myQueue.enqueue (%d);\n", i);
5;
int x =
X = myQueue.dequeue();
i
replit.com
G chegg Write a generic Q...
myQueue.dequeue();
System.out.printf("myQueue.dequeue () gives back %d;\n",x);
25
Line 48: Col 2
myQueue.enqueue(i); System.out.printf("myQueue.enqueue(%d);\n", i);
X = myQueue.dequeue();
i = 6;
Run
System.out.printf("myQueue.dequeue
() gives back %d;\n",x);
System.out.printf("myQueue.dequeue () gives back %d;\n",x);
=
[
1;
i 8;
=
C Home | Chegg.com
myQueue.enqueue(i); System.out.printf("myQueue.enqueue (%d); \n", i);
myQueue.enqueue(i);
System.out.printf("myQueue.enqueue(%d); \n", i);
History
Tests x
Shell x
Resizable Array Impleme...
Chat
Instructions x
Test1
Message: Failed to add remove 100 values
Stack Trace:
Main.java - Queue with a...
> Console x +
✓ Submit Q
invoke(NativeMethodAccessorImpl.java:77)
java.lang. AssertionError: expected:<0> but was:<99>
at org.junit.Assert.fail(Assert.java:88)
at org.junit.Assert.failNotEquals(Assert.java:834)
at org.junit. Assert.assertEquals(Assert.java:645)
at org.junit. Assert.assertEquals(Assert.java:631)
at _test_runnerTestSuite. Test1(_test_runnerTestSuite.java:1
5)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.
invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.
at java.base/jdk.internal.reflect.DelegatingMethodAccessorI
at java.base/java.lang.reflect.Method.invoke(Method.java:56
8)
at org.junit.runners.model. FrameworkMethod$1.runReflectiveC
mpl.invoke(DelegatingMethodAccessorImpl.java:43)
:
at org.junit.internal.runners.model.ReflectiveCallable.run(
all(FrameworkMethod.java:50)
ReflectiveCallable.java:12)
y (FrameworkMethod.java:47)
at org.junit.internal.runners.statements. InvokeMethod. evalu
ate (InvokeMethod.java:17)
at org.junit.runners. ParentRunner.runLeaf (ParentRunner.java
:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild (BlockJ
Unit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild (BlockJ
Unit4ClassRunner.java:57)
at org.junit.runners. ParentRunner $3.run(ParentRunner.java:2
90)
at org.junit.runners. ParentRunner$1.schedule(ParentRunner.j
ava:71)
at org.junit.runners. ParentRunner.runChildren (ParentRunner.
java:288)
at org.junit.runners. ParentRunner.access$000(ParentRunner.j
ava:58)
at org.junit.runners.ParentRunner $2.evaluate(ParentRunner.j
ava: 268)
at org.junit.runners. ParentRunner.run(ParentRunner.java:363
at org.junit.runners.model. FrameworkMethod.invokeExplosivel
Transcribed Image Text:Q Search Course: Data Structures... ✓ Files Config files .replit Main.java .settings .classpath .project Main.class Queue.class Queue.java + maulit siv ✓ Tools Instructions <> Threads CPU DI Debugger Ā Queue with an Array-kivanc120200133 cmpe-211020202 Docs 0 RAM Packages Shell + ? Help ⠀ 0 Y Chat Try Ghostwriter Free Storage Git >_ Console (6) Shell Sıralması (Shell... X Main.java x + 7 8 Main.java 1 public class Main { 2▼ public static void main(String[] args) { 3 4 5 6 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 int i; 1; i = Queue<Integer> myQueue = new Queue<Integer>(); i = 2; i myQueue.enqueue(i); System.out.printf("myQueue.enqueue (%d); \n",i); = i = 4; i myQueue.enqueue(i); System.out.printf("myQueue.enqueue (%d);\n", i); 3; = myQueue.enqueue(i); System.out.printf("myQueue.enqueue (%d); \n",i); b Answered: WRITE JAVA... myQueue.enqueue(i); System.out.printf("myQueue.enqueue (%d);\n", i); 5; int x = X = myQueue.dequeue(); i replit.com G chegg Write a generic Q... myQueue.dequeue(); System.out.printf("myQueue.dequeue () gives back %d;\n",x); 25 Line 48: Col 2 myQueue.enqueue(i); System.out.printf("myQueue.enqueue(%d);\n", i); X = myQueue.dequeue(); i = 6; Run System.out.printf("myQueue.dequeue () gives back %d;\n",x); System.out.printf("myQueue.dequeue () gives back %d;\n",x); = [ 1; i 8; = C Home | Chegg.com myQueue.enqueue(i); System.out.printf("myQueue.enqueue (%d); \n", i); myQueue.enqueue(i); System.out.printf("myQueue.enqueue(%d); \n", i); History Tests x Shell x Resizable Array Impleme... Chat Instructions x Test1 Message: Failed to add remove 100 values Stack Trace: Main.java - Queue with a... > Console x + ✓ Submit Q invoke(NativeMethodAccessorImpl.java:77) java.lang. AssertionError: expected:<0> but was:<99> at org.junit.Assert.fail(Assert.java:88) at org.junit.Assert.failNotEquals(Assert.java:834) at org.junit. Assert.assertEquals(Assert.java:645) at org.junit. Assert.assertEquals(Assert.java:631) at _test_runnerTestSuite. Test1(_test_runnerTestSuite.java:1 5) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl. invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl. at java.base/jdk.internal.reflect.DelegatingMethodAccessorI at java.base/java.lang.reflect.Method.invoke(Method.java:56 8) at org.junit.runners.model. FrameworkMethod$1.runReflectiveC mpl.invoke(DelegatingMethodAccessorImpl.java:43) : at org.junit.internal.runners.model.ReflectiveCallable.run( all(FrameworkMethod.java:50) ReflectiveCallable.java:12) y (FrameworkMethod.java:47) at org.junit.internal.runners.statements. InvokeMethod. evalu ate (InvokeMethod.java:17) at org.junit.runners. ParentRunner.runLeaf (ParentRunner.java :325) at org.junit.runners.BlockJUnit4ClassRunner.runChild (BlockJ Unit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild (BlockJ Unit4ClassRunner.java:57) at org.junit.runners. ParentRunner $3.run(ParentRunner.java:2 90) at org.junit.runners. ParentRunner$1.schedule(ParentRunner.j ava:71) at org.junit.runners. ParentRunner.runChildren (ParentRunner. java:288) at org.junit.runners. ParentRunner.access$000(ParentRunner.j ava:58) at org.junit.runners.ParentRunner $2.evaluate(ParentRunner.j ava: 268) at org.junit.runners. ParentRunner.run(ParentRunner.java:363 at org.junit.runners.model. FrameworkMethod.invokeExplosivel
Expert Solution
steps

Step by step

Solved in 2 steps with 7 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY