SlideShare a Scribd company logo
1 of 10
Download to read offline
Description (Part A) In this lab you will write a Queue implementation called CoolQueue, which
closely matches the java.util.Queue collection, except with fewer methods. Test code is provided
that allows you to compare your queue to the one in java.util.Queue, which you can assume is
completely correct.
Getting Started
Create a project called Lab9 and download following files:
QueueInterface.java
TestProgram.java
CoolQueue.java
Fill in the supplied CoolQueue.java to make it implement the provided QueueInterface methods.
Then use the TestProgram to verify that your code works. Here are the methods in the interface:
public interface QueueInterface {
// Add object onto rear of queue
public abstract boolean add(E item);
// Remove object from front of queue // Throws NoSuchElementException if empty
public abstract E remove();
// Peek object from front of queue // Throws NoSuchElementException if empty
public abstract E element();
// Check for empty
public abstract boolean isEmpty();
// Returns size
public abstract int size();
// Clears queue
public abstract void clear();
// Various searches
public abstract boolean contains(Object o);
// Override toString
public abstract String toString(); }
Instructions
Inherit the interface provided above.
The Queue is a generic data structure, so declare an LinkedList.
HINT: You should use the first entry or head of the LinkedList as the front of the queue.
HINT: You should use the last entry or tail of the LinkedList as the rear of the queue.
You must not use add(), remove(), or element() in the LinkedList object.
You must implement toString() first, format is the same as LinkedList.toString().
Incremental development, so test one method at a time.
Review the TestProgram to see what is tested by each test number, 1 through 7.
Below is the CoolQueue.java:
import java.util.LinkedList;
import java.util.NoSuchElementException;
class CoolQueue implements QueueInterface {
// Underlying data structure
// Default constructor
}
Below is the TestProgram.java:
import java.util.LinkedList;
import java.util.NoSuchElementException;
import java.util.Queue;
import java.util.Random;
public class TestProgram {
static Random random = new Random();
public static void main(String[] args) {
// Make a Java stack
Queue javaQueue = new LinkedList<>();
// Make a student stack
CoolQueue coolQueue = new CoolQueue<>();
// Which test?
int testNumber = Integer.parseInt(args[0]);
switch (testNumber) {
case 1: // testAdd
System.err.println("testAdd: verifying add() method");
pushRandom(javaQueue, 10);
pushRandom(coolQueue, 10);
System.err.println("Java Queue: " + javaQueue);
System.err.println("Cool Queue: " + coolQueue);
break;
case 2: // testRemove
System.err.println("testRemove: verifying remove() method");
pushRandom(javaQueue, 10);
pushRandom(coolQueue, 10);
// Legal removes
for (int i = 0; i < 10; i++) {
System.err.printf("javaQueue.remove(): %4s, coolQueue.remove(): %4s ",
javaQueue.remove(), coolQueue.remove());
}
// Queue empty
try {
javaQueue.remove();
} catch (NoSuchElementException e) {
System.err.println("Java Queue: caught NoSuchElementException");
}
try {
coolQueue.remove();
} catch (NoSuchElementException e) {
System.err.println("Cool Queue: caught NoSuchElementException");
}
break;
case 3: // testElement
System.err.println("testElement: verifying element() method");
pushRandom(javaQueue, 10);
pushRandom(coolQueue, 10);
for (int i = 0; i < 10; i++) {
System.err.printf("javaQueue.element(): %4s, coolQueue.element(): %4s ",
javaQueue.element(), coolQueue.element());
javaQueue.remove();
coolQueue.remove();
}
break;
case 4: // testSize
System.err.println("testSize: verifying size() method");
pushRandom(javaQueue, 23456);
pushRandom(coolQueue, 23456);
for (int i = 0; i < 12123; i++) {
javaQueue.remove();
coolQueue.remove();
}
System.err.printf("javaQueue.size(): %4s, coolQueue.size(): %4s ", javaQueue.size(),
coolQueue.size());
break;
case 5: // testClear
System.err.println("testClear: verifying clear() method");
pushRandom(javaQueue, 23456);
pushRandom(coolQueue, 23456);
javaQueue.clear();
coolQueue.clear();
System.err.printf("javaQueue.size(): %s, coolQueue.size(): %s ", javaQueue.size(),
coolQueue.size());
break;
case 6: // testIsEmpty
System.err.printf("javaQueue.isEmpty(): %4s, coolQueue.isEmpty(): %4s ",
javaQueue.isEmpty(), coolQueue.isEmpty());
javaQueue.add("1111");
coolQueue.add("2222");
System.err.printf("javaQueue.isEmpty(): %4s, coolQueue.isEmpty(): %4s ",
javaQueue.isEmpty(), coolQueue.isEmpty());
javaQueue.remove();
coolQueue.remove();
System.err.printf("javaQueue.isEmpty(): %4s, coolQueue.isEmpty(): %4s ",
javaQueue.isEmpty(), coolQueue.isEmpty());
break;
case 7: // testContains
pushRandom(javaQueue, 1234);
pushRandom(coolQueue, 1234);
System.err.println("javaQueue.contains("7449"): " +
javaQueue.contains("7449"));
System.err.println("coolQueue.contains("7449"): " +
coolQueue.contains("7449"));
System.err.println("javaQueue.contains("4444"): " +
javaQueue.contains("4444"));
System.err.println("coolQueue.contains("4444"): " +
coolQueue.contains("4444"));
break;
}
}
// Initialize stack by pushing random data
private static void pushRandom(Queue queue, int number) {
random.setSeed(1234);
for (int i = 0; i < number; i++) {
queue.add(Integer.toString(random.nextInt(10000)));
}
}
private static void pushRandom(CoolQueue queue, int number) {
random.setSeed(1234);
for (int i = 0; i < number; i++) {
queue.add(Integer.toString(random.nextInt(10000)));
}
}
}
Thanks! I need solution :)
Solution
import java.util.LinkedList;
import java.util.NoSuchElementException;
class CoolQueue implements QueueInterface {
// Underlying data structure
// Default constructor
}
Below is the TestProgram.java:
import java.util.LinkedList;
import java.util.NoSuchElementException;
import java.util.Queue;
import java.util.Random;
public class TestProgram {
static Random random = new Random();
public static void main(String[] args) {
// Make a Java stack
Queue javaQueue = new LinkedList<>();
// Make a student stack
CoolQueue coolQueue = new CoolQueue<>();
// Which test?
int testNumber = Integer.parseInt(args[0]);
switch (testNumber) {
case 1: // testAdd
System.err.println("testAdd: verifying add() method");
pushRandom(javaQueue, 10);
pushRandom(coolQueue, 10);
System.err.println("Java Queue: " + javaQueue);
System.err.println("Cool Queue: " + coolQueue);
break;
case 2: // testRemove
System.err.println("testRemove: verifying remove() method");
pushRandom(javaQueue, 10);
pushRandom(coolQueue, 10);
// Legal removes
for (int i = 0; i < 10; i++) {
System.err.printf("javaQueue.remove(): %4s, coolQueue.remove(): %4s ",
javaQueue.remove(), coolQueue.remove());
}
// Queue empty
try {
javaQueue.remove();
} catch (NoSuchElementException e) {
System.err.println("Java Queue: caught NoSuchElementException");
}
try {
coolQueue.remove();
} catch (NoSuchElementException e) {
System.err.println("Cool Queue: caught NoSuchElementException");
}
break;
case 3: // testElement
System.err.println("testElement: verifying element() method");
pushRandom(javaQueue, 10);
pushRandom(coolQueue, 10);
for (int i = 0; i < 10; i++) {
System.err.printf("javaQueue.element(): %4s, coolQueue.element(): %4s ",
javaQueue.element(), coolQueue.element());
javaQueue.remove();
coolQueue.remove();
}
break;
case 4: // testSize
System.err.println("testSize: verifying size() method");
pushRandom(javaQueue, 23456);
pushRandom(coolQueue, 23456);
for (int i = 0; i < 12123; i++) {
javaQueue.remove();
coolQueue.remove();
}
System.err.printf("javaQueue.size(): %4s, coolQueue.size(): %4s ", javaQueue.size(),
coolQueue.size());
break;
case 5: // testClear
System.err.println("testClear: verifying clear() method");
pushRandom(javaQueue, 23456);
pushRandom(coolQueue, 23456);
javaQueue.clear();
coolQueue.clear();
System.err.printf("javaQueue.size(): %s, coolQueue.size(): %s ", javaQueue.size(),
coolQueue.size());
break;
case 6: // testIsEmpty
System.err.printf("javaQueue.isEmpty(): %4s, coolQueue.isEmpty(): %4s ",
javaQueue.isEmpty(), coolQueue.isEmpty());
javaQueue.add("1111");
coolQueue.add("2222");
System.err.printf("javaQueue.isEmpty(): %4s, coolQueue.isEmpty(): %4s ",
javaQueue.isEmpty(), coolQueue.isEmpty());
javaQueue.remove();
coolQueue.remove();
System.err.printf("javaQueue.isEmpty(): %4s, coolQueue.isEmpty(): %4s ",
javaQueue.isEmpty(), coolQueue.isEmpty());
break;
case 7: // testContains
pushRandom(javaQueue, 1234);
pushRandom(coolQueue, 1234);
System.err.println("javaQueue.contains("7449"): " +
javaQueue.contains("7449"));
System.err.println("coolQueue.contains("7449"): " +
coolQueue.contains("7449"));
System.err.println("javaQueue.contains("4444"): " +
javaQueue.contains("4444"));
System.err.println("coolQueue.contains("4444"): " +
coolQueue.contains("4444"));
break;
}
}
// Initialize stack by pushing random data
private static void pushRandom(Queue queue, int number) {
random.setSeed(1234);
for (int i = 0; i < number; i++) {
queue.add(Integer.toString(random.nextInt(10000)));
}
}
private static void pushRandom(CoolQueue queue, int number) {
random.setSeed(1234);
for (int i = 0; i < number; i++) {
queue.add(Integer.toString(random.nextInt(10000)));
}
}
}

More Related Content

Similar to Description (Part A) In this lab you will write a Queue implementati.pdf

33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good TestsTomek Kaczanowski
 
Testing, Performance Analysis, and jQuery 1.4
Testing, Performance Analysis, and jQuery 1.4Testing, Performance Analysis, and jQuery 1.4
Testing, Performance Analysis, and jQuery 1.4jeresig
 
Java Programs
Java ProgramsJava Programs
Java Programsvvpadhu
 
Understanding JavaScript Testing
Understanding JavaScript TestingUnderstanding JavaScript Testing
Understanding JavaScript Testingjeresig
 
Pragmatic unittestingwithj unit
Pragmatic unittestingwithj unitPragmatic unittestingwithj unit
Pragmatic unittestingwithj unitliminescence
 
Code Kata: String Calculator in Flex
Code Kata: String Calculator in FlexCode Kata: String Calculator in Flex
Code Kata: String Calculator in FlexChris Farrell
 
Introduction to TDD with FlexUnit
Introduction to TDD with FlexUnitIntroduction to TDD with FlexUnit
Introduction to TDD with FlexUnitAnupom Syam
 
모던자바의 역습
모던자바의 역습모던자바의 역습
모던자바의 역습DoHyun Jung
 
Intro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJSIntro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJSJim Lynch
 
We Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentWe Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentAll Things Open
 
OCJP Samples Questions: Exceptions and assertions
OCJP Samples Questions: Exceptions and assertionsOCJP Samples Questions: Exceptions and assertions
OCJP Samples Questions: Exceptions and assertionsHari kiran G
 
Data-Driven Unit Testing for Java
Data-Driven Unit Testing for JavaData-Driven Unit Testing for Java
Data-Driven Unit Testing for JavaDenilson Nastacio
 
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdfImplement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdfkostikjaylonshaewe47
 
Selenium Webdriver with data driven framework
Selenium Webdriver with data driven frameworkSelenium Webdriver with data driven framework
Selenium Webdriver with data driven frameworkDavid Rajah Selvaraj
 

Similar to Description (Part A) In this lab you will write a Queue implementati.pdf (20)

33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests
 
Testing, Performance Analysis, and jQuery 1.4
Testing, Performance Analysis, and jQuery 1.4Testing, Performance Analysis, and jQuery 1.4
Testing, Performance Analysis, and jQuery 1.4
 
Java Programs
Java ProgramsJava Programs
Java Programs
 
Understanding JavaScript Testing
Understanding JavaScript TestingUnderstanding JavaScript Testing
Understanding JavaScript Testing
 
Pragmatic unittestingwithj unit
Pragmatic unittestingwithj unitPragmatic unittestingwithj unit
Pragmatic unittestingwithj unit
 
Code Kata: String Calculator in Flex
Code Kata: String Calculator in FlexCode Kata: String Calculator in Flex
Code Kata: String Calculator in Flex
 
Introduction to TDD with FlexUnit
Introduction to TDD with FlexUnitIntroduction to TDD with FlexUnit
Introduction to TDD with FlexUnit
 
Java custom annotations example
Java custom annotations exampleJava custom annotations example
Java custom annotations example
 
Java programs
Java programsJava programs
Java programs
 
모던자바의 역습
모던자바의 역습모던자바의 역습
모던자바의 역습
 
Intro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJSIntro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJS
 
Java Concurrency
Java ConcurrencyJava Concurrency
Java Concurrency
 
We Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentWe Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End Development
 
FunctionalInterfaces
FunctionalInterfacesFunctionalInterfaces
FunctionalInterfaces
 
FunctionalInterfaces
FunctionalInterfacesFunctionalInterfaces
FunctionalInterfaces
 
OCJP Samples Questions: Exceptions and assertions
OCJP Samples Questions: Exceptions and assertionsOCJP Samples Questions: Exceptions and assertions
OCJP Samples Questions: Exceptions and assertions
 
Data-Driven Unit Testing for Java
Data-Driven Unit Testing for JavaData-Driven Unit Testing for Java
Data-Driven Unit Testing for Java
 
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdfImplement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
 
Selenium Webdriver with data driven framework
Selenium Webdriver with data driven frameworkSelenium Webdriver with data driven framework
Selenium Webdriver with data driven framework
 
Test program
Test programTest program
Test program
 

More from rishabjain5053

write a short essay report to describe a topic of your interest rela.pdf
write a short essay report to describe a topic of your interest rela.pdfwrite a short essay report to describe a topic of your interest rela.pdf
write a short essay report to describe a topic of your interest rela.pdfrishabjain5053
 
Write a C++ program to do the followingProject Name Computer Sho.pdf
Write a C++ program to do the followingProject Name Computer Sho.pdfWrite a C++ program to do the followingProject Name Computer Sho.pdf
Write a C++ program to do the followingProject Name Computer Sho.pdfrishabjain5053
 
Which statement pertaining to Port Scanning is FALSEA technique use.pdf
Which statement pertaining to Port Scanning is FALSEA technique use.pdfWhich statement pertaining to Port Scanning is FALSEA technique use.pdf
Which statement pertaining to Port Scanning is FALSEA technique use.pdfrishabjain5053
 
When did almost all animal phyla divergeSolutionAccording to .pdf
When did almost all animal phyla divergeSolutionAccording to .pdfWhen did almost all animal phyla divergeSolutionAccording to .pdf
When did almost all animal phyla divergeSolutionAccording to .pdfrishabjain5053
 
What is the nipah virus Describe mechanism of infection How is it .pdf
What is the nipah virus Describe mechanism of infection How is it .pdfWhat is the nipah virus Describe mechanism of infection How is it .pdf
What is the nipah virus Describe mechanism of infection How is it .pdfrishabjain5053
 
What is organizational inertia List some sources of inertia in a co.pdf
What is organizational inertia List some sources of inertia in a co.pdfWhat is organizational inertia List some sources of inertia in a co.pdf
What is organizational inertia List some sources of inertia in a co.pdfrishabjain5053
 
Use fundamental identities to write tan t sec2t in terms of sint only.pdf
Use fundamental identities to write tan t sec2t in terms of sint only.pdfUse fundamental identities to write tan t sec2t in terms of sint only.pdf
Use fundamental identities to write tan t sec2t in terms of sint only.pdfrishabjain5053
 
Twenty-five people responded to a questionnaire about what types of p.pdf
Twenty-five people responded to a questionnaire about what types of p.pdfTwenty-five people responded to a questionnaire about what types of p.pdf
Twenty-five people responded to a questionnaire about what types of p.pdfrishabjain5053
 
The universe began 13 7 billion years ago, is most directly an exa.pdf
The universe began 13 7 billion years ago,  is most directly an exa.pdfThe universe began 13 7 billion years ago,  is most directly an exa.pdf
The universe began 13 7 billion years ago, is most directly an exa.pdfrishabjain5053
 
The Stevens Company provided $57000 of services on acco.pdf
The Stevens Company provided $57000 of services on acco.pdfThe Stevens Company provided $57000 of services on acco.pdf
The Stevens Company provided $57000 of services on acco.pdfrishabjain5053
 
The papillae on the tongue that do not contain any taste buds are the.pdf
The papillae on the tongue that do not contain any taste buds are the.pdfThe papillae on the tongue that do not contain any taste buds are the.pdf
The papillae on the tongue that do not contain any taste buds are the.pdfrishabjain5053
 
QUESTION 13 Which of the following benefits is a component of Social .pdf
QUESTION 13 Which of the following benefits is a component of Social .pdfQUESTION 13 Which of the following benefits is a component of Social .pdf
QUESTION 13 Which of the following benefits is a component of Social .pdfrishabjain5053
 
Padre, Inc., buys 80 percent of the outstanding common stock of Sier.pdf
Padre, Inc., buys 80 percent of the outstanding common stock of Sier.pdfPadre, Inc., buys 80 percent of the outstanding common stock of Sier.pdf
Padre, Inc., buys 80 percent of the outstanding common stock of Sier.pdfrishabjain5053
 
Operating Systems Structure1- Explain briefly why the objectives o.pdf
Operating Systems Structure1- Explain briefly why the objectives o.pdfOperating Systems Structure1- Explain briefly why the objectives o.pdf
Operating Systems Structure1- Explain briefly why the objectives o.pdfrishabjain5053
 
Need help with this java code. fill in lines where needed. Also, not.pdf
Need help with this java code. fill in lines where needed. Also, not.pdfNeed help with this java code. fill in lines where needed. Also, not.pdf
Need help with this java code. fill in lines where needed. Also, not.pdfrishabjain5053
 
IP has no mechanism for error reporting or error-correcting. ICMPv4 .pdf
IP has no mechanism for error reporting or error-correcting. ICMPv4 .pdfIP has no mechanism for error reporting or error-correcting. ICMPv4 .pdf
IP has no mechanism for error reporting or error-correcting. ICMPv4 .pdfrishabjain5053
 
Informed Consent is a significant requirement for all provider types.pdf
Informed Consent is a significant requirement for all provider types.pdfInformed Consent is a significant requirement for all provider types.pdf
Informed Consent is a significant requirement for all provider types.pdfrishabjain5053
 
In the MVC Architecture, why is it important to keep the model, view.pdf
In the MVC Architecture, why is it important to keep the model, view.pdfIn the MVC Architecture, why is it important to keep the model, view.pdf
In the MVC Architecture, why is it important to keep the model, view.pdfrishabjain5053
 
in roughly 400 words please describe3 affective outcomes of diver.pdf
in roughly 400 words please describe3 affective outcomes of diver.pdfin roughly 400 words please describe3 affective outcomes of diver.pdf
in roughly 400 words please describe3 affective outcomes of diver.pdfrishabjain5053
 
Im having issues with two homework questions. I get the gist of th.pdf
Im having issues with two homework questions. I get the gist of th.pdfIm having issues with two homework questions. I get the gist of th.pdf
Im having issues with two homework questions. I get the gist of th.pdfrishabjain5053
 

More from rishabjain5053 (20)

write a short essay report to describe a topic of your interest rela.pdf
write a short essay report to describe a topic of your interest rela.pdfwrite a short essay report to describe a topic of your interest rela.pdf
write a short essay report to describe a topic of your interest rela.pdf
 
Write a C++ program to do the followingProject Name Computer Sho.pdf
Write a C++ program to do the followingProject Name Computer Sho.pdfWrite a C++ program to do the followingProject Name Computer Sho.pdf
Write a C++ program to do the followingProject Name Computer Sho.pdf
 
Which statement pertaining to Port Scanning is FALSEA technique use.pdf
Which statement pertaining to Port Scanning is FALSEA technique use.pdfWhich statement pertaining to Port Scanning is FALSEA technique use.pdf
Which statement pertaining to Port Scanning is FALSEA technique use.pdf
 
When did almost all animal phyla divergeSolutionAccording to .pdf
When did almost all animal phyla divergeSolutionAccording to .pdfWhen did almost all animal phyla divergeSolutionAccording to .pdf
When did almost all animal phyla divergeSolutionAccording to .pdf
 
What is the nipah virus Describe mechanism of infection How is it .pdf
What is the nipah virus Describe mechanism of infection How is it .pdfWhat is the nipah virus Describe mechanism of infection How is it .pdf
What is the nipah virus Describe mechanism of infection How is it .pdf
 
What is organizational inertia List some sources of inertia in a co.pdf
What is organizational inertia List some sources of inertia in a co.pdfWhat is organizational inertia List some sources of inertia in a co.pdf
What is organizational inertia List some sources of inertia in a co.pdf
 
Use fundamental identities to write tan t sec2t in terms of sint only.pdf
Use fundamental identities to write tan t sec2t in terms of sint only.pdfUse fundamental identities to write tan t sec2t in terms of sint only.pdf
Use fundamental identities to write tan t sec2t in terms of sint only.pdf
 
Twenty-five people responded to a questionnaire about what types of p.pdf
Twenty-five people responded to a questionnaire about what types of p.pdfTwenty-five people responded to a questionnaire about what types of p.pdf
Twenty-five people responded to a questionnaire about what types of p.pdf
 
The universe began 13 7 billion years ago, is most directly an exa.pdf
The universe began 13 7 billion years ago,  is most directly an exa.pdfThe universe began 13 7 billion years ago,  is most directly an exa.pdf
The universe began 13 7 billion years ago, is most directly an exa.pdf
 
The Stevens Company provided $57000 of services on acco.pdf
The Stevens Company provided $57000 of services on acco.pdfThe Stevens Company provided $57000 of services on acco.pdf
The Stevens Company provided $57000 of services on acco.pdf
 
The papillae on the tongue that do not contain any taste buds are the.pdf
The papillae on the tongue that do not contain any taste buds are the.pdfThe papillae on the tongue that do not contain any taste buds are the.pdf
The papillae on the tongue that do not contain any taste buds are the.pdf
 
QUESTION 13 Which of the following benefits is a component of Social .pdf
QUESTION 13 Which of the following benefits is a component of Social .pdfQUESTION 13 Which of the following benefits is a component of Social .pdf
QUESTION 13 Which of the following benefits is a component of Social .pdf
 
Padre, Inc., buys 80 percent of the outstanding common stock of Sier.pdf
Padre, Inc., buys 80 percent of the outstanding common stock of Sier.pdfPadre, Inc., buys 80 percent of the outstanding common stock of Sier.pdf
Padre, Inc., buys 80 percent of the outstanding common stock of Sier.pdf
 
Operating Systems Structure1- Explain briefly why the objectives o.pdf
Operating Systems Structure1- Explain briefly why the objectives o.pdfOperating Systems Structure1- Explain briefly why the objectives o.pdf
Operating Systems Structure1- Explain briefly why the objectives o.pdf
 
Need help with this java code. fill in lines where needed. Also, not.pdf
Need help with this java code. fill in lines where needed. Also, not.pdfNeed help with this java code. fill in lines where needed. Also, not.pdf
Need help with this java code. fill in lines where needed. Also, not.pdf
 
IP has no mechanism for error reporting or error-correcting. ICMPv4 .pdf
IP has no mechanism for error reporting or error-correcting. ICMPv4 .pdfIP has no mechanism for error reporting or error-correcting. ICMPv4 .pdf
IP has no mechanism for error reporting or error-correcting. ICMPv4 .pdf
 
Informed Consent is a significant requirement for all provider types.pdf
Informed Consent is a significant requirement for all provider types.pdfInformed Consent is a significant requirement for all provider types.pdf
Informed Consent is a significant requirement for all provider types.pdf
 
In the MVC Architecture, why is it important to keep the model, view.pdf
In the MVC Architecture, why is it important to keep the model, view.pdfIn the MVC Architecture, why is it important to keep the model, view.pdf
In the MVC Architecture, why is it important to keep the model, view.pdf
 
in roughly 400 words please describe3 affective outcomes of diver.pdf
in roughly 400 words please describe3 affective outcomes of diver.pdfin roughly 400 words please describe3 affective outcomes of diver.pdf
in roughly 400 words please describe3 affective outcomes of diver.pdf
 
Im having issues with two homework questions. I get the gist of th.pdf
Im having issues with two homework questions. I get the gist of th.pdfIm having issues with two homework questions. I get the gist of th.pdf
Im having issues with two homework questions. I get the gist of th.pdf
 

Recently uploaded

Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 

Recently uploaded (20)

Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 

Description (Part A) In this lab you will write a Queue implementati.pdf

  • 1. Description (Part A) In this lab you will write a Queue implementation called CoolQueue, which closely matches the java.util.Queue collection, except with fewer methods. Test code is provided that allows you to compare your queue to the one in java.util.Queue, which you can assume is completely correct. Getting Started Create a project called Lab9 and download following files: QueueInterface.java TestProgram.java CoolQueue.java Fill in the supplied CoolQueue.java to make it implement the provided QueueInterface methods. Then use the TestProgram to verify that your code works. Here are the methods in the interface: public interface QueueInterface { // Add object onto rear of queue public abstract boolean add(E item); // Remove object from front of queue // Throws NoSuchElementException if empty public abstract E remove(); // Peek object from front of queue // Throws NoSuchElementException if empty public abstract E element(); // Check for empty public abstract boolean isEmpty(); // Returns size public abstract int size(); // Clears queue public abstract void clear(); // Various searches public abstract boolean contains(Object o); // Override toString public abstract String toString(); } Instructions Inherit the interface provided above. The Queue is a generic data structure, so declare an LinkedList. HINT: You should use the first entry or head of the LinkedList as the front of the queue. HINT: You should use the last entry or tail of the LinkedList as the rear of the queue. You must not use add(), remove(), or element() in the LinkedList object. You must implement toString() first, format is the same as LinkedList.toString().
  • 2. Incremental development, so test one method at a time. Review the TestProgram to see what is tested by each test number, 1 through 7. Below is the CoolQueue.java: import java.util.LinkedList; import java.util.NoSuchElementException; class CoolQueue implements QueueInterface { // Underlying data structure // Default constructor } Below is the TestProgram.java: import java.util.LinkedList; import java.util.NoSuchElementException; import java.util.Queue; import java.util.Random; public class TestProgram { static Random random = new Random(); public static void main(String[] args) { // Make a Java stack Queue javaQueue = new LinkedList<>(); // Make a student stack CoolQueue coolQueue = new CoolQueue<>(); // Which test? int testNumber = Integer.parseInt(args[0]);
  • 3. switch (testNumber) { case 1: // testAdd System.err.println("testAdd: verifying add() method"); pushRandom(javaQueue, 10); pushRandom(coolQueue, 10); System.err.println("Java Queue: " + javaQueue); System.err.println("Cool Queue: " + coolQueue); break; case 2: // testRemove System.err.println("testRemove: verifying remove() method"); pushRandom(javaQueue, 10); pushRandom(coolQueue, 10); // Legal removes for (int i = 0; i < 10; i++) { System.err.printf("javaQueue.remove(): %4s, coolQueue.remove(): %4s ", javaQueue.remove(), coolQueue.remove()); } // Queue empty try { javaQueue.remove(); } catch (NoSuchElementException e) { System.err.println("Java Queue: caught NoSuchElementException"); } try { coolQueue.remove(); } catch (NoSuchElementException e) { System.err.println("Cool Queue: caught NoSuchElementException"); } break;
  • 4. case 3: // testElement System.err.println("testElement: verifying element() method"); pushRandom(javaQueue, 10); pushRandom(coolQueue, 10); for (int i = 0; i < 10; i++) { System.err.printf("javaQueue.element(): %4s, coolQueue.element(): %4s ", javaQueue.element(), coolQueue.element()); javaQueue.remove(); coolQueue.remove(); } break; case 4: // testSize System.err.println("testSize: verifying size() method"); pushRandom(javaQueue, 23456); pushRandom(coolQueue, 23456); for (int i = 0; i < 12123; i++) { javaQueue.remove(); coolQueue.remove(); } System.err.printf("javaQueue.size(): %4s, coolQueue.size(): %4s ", javaQueue.size(), coolQueue.size()); break; case 5: // testClear System.err.println("testClear: verifying clear() method"); pushRandom(javaQueue, 23456); pushRandom(coolQueue, 23456); javaQueue.clear(); coolQueue.clear(); System.err.printf("javaQueue.size(): %s, coolQueue.size(): %s ", javaQueue.size(), coolQueue.size());
  • 5. break; case 6: // testIsEmpty System.err.printf("javaQueue.isEmpty(): %4s, coolQueue.isEmpty(): %4s ", javaQueue.isEmpty(), coolQueue.isEmpty()); javaQueue.add("1111"); coolQueue.add("2222"); System.err.printf("javaQueue.isEmpty(): %4s, coolQueue.isEmpty(): %4s ", javaQueue.isEmpty(), coolQueue.isEmpty()); javaQueue.remove(); coolQueue.remove(); System.err.printf("javaQueue.isEmpty(): %4s, coolQueue.isEmpty(): %4s ", javaQueue.isEmpty(), coolQueue.isEmpty()); break; case 7: // testContains pushRandom(javaQueue, 1234); pushRandom(coolQueue, 1234); System.err.println("javaQueue.contains("7449"): " + javaQueue.contains("7449")); System.err.println("coolQueue.contains("7449"): " + coolQueue.contains("7449")); System.err.println("javaQueue.contains("4444"): " + javaQueue.contains("4444")); System.err.println("coolQueue.contains("4444"): " + coolQueue.contains("4444")); break; } } // Initialize stack by pushing random data private static void pushRandom(Queue queue, int number) { random.setSeed(1234); for (int i = 0; i < number; i++) {
  • 6. queue.add(Integer.toString(random.nextInt(10000))); } } private static void pushRandom(CoolQueue queue, int number) { random.setSeed(1234); for (int i = 0; i < number; i++) { queue.add(Integer.toString(random.nextInt(10000))); } } } Thanks! I need solution :) Solution import java.util.LinkedList; import java.util.NoSuchElementException; class CoolQueue implements QueueInterface { // Underlying data structure // Default constructor } Below is the TestProgram.java: import java.util.LinkedList; import java.util.NoSuchElementException; import java.util.Queue; import java.util.Random; public class TestProgram { static Random random = new Random(); public static void main(String[] args) {
  • 7. // Make a Java stack Queue javaQueue = new LinkedList<>(); // Make a student stack CoolQueue coolQueue = new CoolQueue<>(); // Which test? int testNumber = Integer.parseInt(args[0]); switch (testNumber) { case 1: // testAdd System.err.println("testAdd: verifying add() method"); pushRandom(javaQueue, 10); pushRandom(coolQueue, 10); System.err.println("Java Queue: " + javaQueue); System.err.println("Cool Queue: " + coolQueue); break; case 2: // testRemove System.err.println("testRemove: verifying remove() method"); pushRandom(javaQueue, 10); pushRandom(coolQueue, 10); // Legal removes for (int i = 0; i < 10; i++) { System.err.printf("javaQueue.remove(): %4s, coolQueue.remove(): %4s ", javaQueue.remove(), coolQueue.remove()); } // Queue empty try { javaQueue.remove(); } catch (NoSuchElementException e) {
  • 8. System.err.println("Java Queue: caught NoSuchElementException"); } try { coolQueue.remove(); } catch (NoSuchElementException e) { System.err.println("Cool Queue: caught NoSuchElementException"); } break; case 3: // testElement System.err.println("testElement: verifying element() method"); pushRandom(javaQueue, 10); pushRandom(coolQueue, 10); for (int i = 0; i < 10; i++) { System.err.printf("javaQueue.element(): %4s, coolQueue.element(): %4s ", javaQueue.element(), coolQueue.element()); javaQueue.remove(); coolQueue.remove(); } break; case 4: // testSize System.err.println("testSize: verifying size() method"); pushRandom(javaQueue, 23456); pushRandom(coolQueue, 23456); for (int i = 0; i < 12123; i++) { javaQueue.remove(); coolQueue.remove(); } System.err.printf("javaQueue.size(): %4s, coolQueue.size(): %4s ", javaQueue.size(), coolQueue.size()); break;
  • 9. case 5: // testClear System.err.println("testClear: verifying clear() method"); pushRandom(javaQueue, 23456); pushRandom(coolQueue, 23456); javaQueue.clear(); coolQueue.clear(); System.err.printf("javaQueue.size(): %s, coolQueue.size(): %s ", javaQueue.size(), coolQueue.size()); break; case 6: // testIsEmpty System.err.printf("javaQueue.isEmpty(): %4s, coolQueue.isEmpty(): %4s ", javaQueue.isEmpty(), coolQueue.isEmpty()); javaQueue.add("1111"); coolQueue.add("2222"); System.err.printf("javaQueue.isEmpty(): %4s, coolQueue.isEmpty(): %4s ", javaQueue.isEmpty(), coolQueue.isEmpty()); javaQueue.remove(); coolQueue.remove(); System.err.printf("javaQueue.isEmpty(): %4s, coolQueue.isEmpty(): %4s ", javaQueue.isEmpty(), coolQueue.isEmpty()); break; case 7: // testContains pushRandom(javaQueue, 1234); pushRandom(coolQueue, 1234); System.err.println("javaQueue.contains("7449"): " + javaQueue.contains("7449")); System.err.println("coolQueue.contains("7449"): " + coolQueue.contains("7449")); System.err.println("javaQueue.contains("4444"): " + javaQueue.contains("4444")); System.err.println("coolQueue.contains("4444"): " +
  • 10. coolQueue.contains("4444")); break; } } // Initialize stack by pushing random data private static void pushRandom(Queue queue, int number) { random.setSeed(1234); for (int i = 0; i < number; i++) { queue.add(Integer.toString(random.nextInt(10000))); } } private static void pushRandom(CoolQueue queue, int number) { random.setSeed(1234); for (int i = 0; i < number; i++) { queue.add(Integer.toString(random.nextInt(10000))); } } }