Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Based on the information I provided to complete the coding assignment. Attached are pictures below for requirement I attached all the files as well as

Based on the information I provided to complete the coding assignment. Attached are pictures below for requirement

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

I attached all the files as well as the information needed in the assignment below

Please make sure to follow the instruction to finish the code.

Also please finish the extra credit part of the assignment if possible.

image text in transcribed

image text in transcribed

** Queue.java ** /** * The class defines the Queue interface * * @param  generic data type */ public interface Queue { /** * The method adds the specified element to the tail/rear/last of the queue. * @param data the element to add to the queue */ void add(Type data); /** * The method removes and returns the front/head element from the queue. * @throws EmptyCollectionException if the queue is empty. * @return the front/head element from the queue */ Type remove(); /** * The method eturns the front/head element from the queue (without removing the element. * * @throws EmptyCollectionException if the queue is empty. * @return the front element from the queue */ Type peek(); /** * The method indicates the number of elements in the queue * @return the count of elements currently in the queue */ int size(); /** * The method checks if the queue is empty or not * * @return true if the queue contains no elements otherwise false */ boolean isEmpty(); }

** Deque.java **

public interface Deque extends Queue { /** * The method adds element to the back * @param data the element is added to the back */ void addRear(Type data); /** * The method adds element to the front * @param data the element is added to the front */ void addFront(Type data); /** * The method removes element from the back */ Type removeRear(); /** * The method removes element from the front */ Type removeFront(); /** * The method examines element from the back */ Type peekRear(); /** * The method examines the element from the front */ Type peekFront(); }

** EmptyCollectionException.java **

/** * The class represents the exception when a collection is empty. */ public class EmptyCollectionException extends RuntimeException { private static final long serialVersionUID = 8084488539524488189L; /** * The constructor sets up this exception with an appropriate message. * @param message the error message */ public EmptyCollectionException(final String message) { super(message); } }

** LinkedQueue.java **

/** * The class defines a node-based queue. * @param  the generic data type */ public class LinkedQueue implements Queue { /** * The number of elements contained in the queue. */ protected int size; /** * A reference to the first node in the queue. (The 'head' of the queue.) */ protected Node head; /** * A reference to the last node in the queue. (The 'tail' of the queue.) */ private Node tail; /** * The constructor initializes an empty queue. */ public LinkedQueue() { size = 0; head = null; tail = null; } @Override public void add(final Type theElement) { if (size == 0) { // base case when the queue is empty head = new Node(theElement); tail = head; } else { // regular case when the queue is not empty tail.next = new Node(theElement); tail = tail.next; } size++; } @Override public Type remove() { if (size == 0) throw new EmptyCollectionException("queue"); final Type returnValue = head.data; head = head.next; size--; return returnValue; } @Override public Type peek() { if (size == 0) { throw new EmptyCollectionException("queue"); } return head.data; } @Override public int size() { return size; } @Override public boolean isEmpty() { return size == 0; } /** * The method returns the linked queue in string format as below * 

* The format of the returned String is: Head -> 8, 6, 7, 5, 3, 0, 9 */ @Override public String toString() { if (size == 0) return "head ->"; final StringBuilder buffer = new StringBuilder(); buffer.append("head -> "); Node current = head; for (int i = 0; i generic data type */ protected class Node { /** * A reference to the next node in the linked structure. */ protected Node next; /** * A reference to the data element held in this node. */ protected final Type data; /** * The constructor initializes the node using the specified data element. * * @param data the data element held in this node */ Node(final Type data) { this(data, null); } /** * The constructor initializes the node using the specified data element and the specified next * node. * * @param data the data element held in this node * @param next the next node in the linked structure */ Node(final Type data, final Node next) { this.data = data; this.next = next; } } }

** LinkedQueueTest.java **

import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; /** * The class is a unit testing for the {@link LinkedQueue} * */ public class LinkedQueueTest { /** * A generic simple LinkedQueue to test. */ private LinkedQueue myQueue; /** * The method initializes the queue before the test. * * @throws java.lang.Exception */ @BeforeEach void setUp() throws Exception { myQueue = new LinkedQueue(); } /** * Test method for{LinkedQueue#LinkedQueue()}. */ @Test void testLinkedQueue() { assertNotNull("myQueue was not instantiated!", myQueue); assertEquals("myQueue should be size zero!", 0, myQueue.size()); assertTrue("myQueue should be empty!", myQueue.isEmpty()); } @Test void testLinkedQueueAdd1() { myQueue.add(6); assertEquals("add failed: queue size expected 1 instead of " + myQueue.size(), 1, myQueue.size()); assertEquals("to string failed: expected head -> 6 instead of " + myQueue.toString(), myQueue.toString(), "head -> 6"); } @Test void testLinkedQueueAdd2() { myQueue.add(6); myQueue.add(-12); assertEquals("add failed: queue size expected 2 instead of " + myQueue.size(), 2, myQueue.size()); assertEquals("to string failed: expected head -> 6, -12 instead of " + myQueue.toString(), myQueue.toString(), "head -> 6, -12"); } @Test void testLinkedQueueAdd3() { myQueue.add(6); myQueue.add(-12); myQueue.add(5025); assertEquals("add failed: queue size expected 3 instead of " + myQueue.size(), 3, myQueue.size()); assertEquals("to string failed: expected head -> 6, -12, 5025 instead of " + myQueue.toString(), myQueue.toString(), "head -> 6, -12, 5025"); } @Test void testLinkedQueueAddNull() { myQueue.add(6); myQueue.add(null); myQueue.add(-12); assertEquals("add failed: queue size expected 3 instead of " + myQueue.size(), 3, myQueue.size()); assertEquals("to string failed: expected head -> 6, null, -12 instead of " + myQueue.toString(), myQueue.toString(), "head -> 6, null, -12"); } @Test void testLinkedQueueRemove1() { myQueue.add(6); myQueue.remove(); assertEquals("add failed: queue size expected 0 instead of " + myQueue.size(), 0, myQueue.size()); assertEquals("to string failed: expected head -> instead of " + myQueue.toString(), myQueue.toString(), "head ->"); } @Test void testLinkedQueueRemove2() { myQueue.add(6); myQueue.add(-12); myQueue.remove(); assertEquals("add failed: queue size expected 1 instead of " + myQueue.size(), 1, myQueue.size()); assertEquals("to string failed: expected head -> -12 instead of " + myQueue.toString(), myQueue.toString(), "head -> -12"); } @Test void testLinkedQueueRemove3() { myQueue.add(6); myQueue.add(-12); myQueue.add(5025); myQueue.remove(); assertEquals("add failed: queue size expected 2 instead of " + myQueue.size(), 2, myQueue.size()); assertEquals("to string failed: expected head -> -12, 5025 instead of " + myQueue.toString(), myQueue.toString(), "head -> -12, 5025"); } @Test void testLinkedQueueRemove4() { myQueue.add(6); myQueue.add(-12); myQueue.add(5025); myQueue.add(0); myQueue.remove(); myQueue.remove(); assertEquals("add failed: queue size expected 2 instead of " + myQueue.size(), 2, myQueue.size()); assertEquals("to string failed: expected head -> 5025, 0 instead of " + myQueue.toString(), myQueue.toString(), "head -> 5025, 0"); } @Test void testLinkedQueuePeek1() { myQueue.add(6); assertEquals("add failed: queue size expected 1 instead of " + myQueue.size(), 1, myQueue.size()); assertTrue("peek failed: expected 6", myQueue.peek() == 6); } @Test void testLinkedQueuePeek2() { myQueue.add(6); myQueue.add(-12); assertEquals("add failed: queue size expected 2 instead of " + myQueue.size(), 2, myQueue.size()); assertTrue("peek failed: expected 6", myQueue.peek() == 6); } @Test void testLinkedQueueIsEmpty() { assertEquals("add failed: queue size expected 0 instead of " + myQueue.size(), 0, myQueue.size()); assertEquals("toString failed: expected head -> instead of " + myQueue.toString(), "head ->", myQueue.toString()); assertTrue("isEmpty() failed: expected True", myQueue.isEmpty()); } @Test public final void testLinkedQueueRemoveException() { try { myQueue.remove(); assertTrue("exception: expected to throw EmptyCollectionException", false); } catch (EmptyCollectionException e) { assertTrue(true); } } @Test public final void testLinkedQueuePeekException() { try { myQueue.peek(); assertTrue("exception: expected to throw EmptyCollectionException", false); } catch (EmptyCollectionException e) { assertTrue(true); } } }

** LinkedDeque.java **

/** * The class defines the node-based queue * @param  the generic data type */ public class LinkedDeque extends LinkedQueue implements Deque { /** * The constructor initializes an empty queue. */ public LinkedDeque() { // TODO IMPLEMENT CODE HERE } @Override public void addRear(Type data) { // TODO IMPLEMENT CODE HERE } @Override public void addFront(Type theElement) { // TODO IMPLEMENT CODE HERE } @Override public Type removeRear() { // TODO IMPLEMENT CODE HERE return null; } @Override public Type removeFront() { // TODO IMPLEMENT CODE HERE return null; } @Override public Type peekRear() { // TODO IMPLEMENT CODE HERE return null; } @Override public Type peekFront() { // TODO IMPLEMENT CODE HERE return null; } } 

** LinkedDequeTest.java **

import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; /** * The class is a unit testing for the {@link LinkedDeque} * * @author */ public class LinkedDequeTest { /** * A generic simple LinkedDeque to test. */ private LinkedDeque myQueue; /** * The method initializes the queue before the test. * * @throws java.lang.Exception */ @BeforeEach void setUp() throws Exception { myQueue = new LinkedDeque(); } /** * Test method for{@link LinkedDeque#LinkedDeque()}. */ @Test void testLinkedDeque() { // TODO Do nothing but check the size and if the queue is empty. } @Test void testAddRear1() { // TODO Add one element to the back and check size and queue in string format. } @Test void testAddRear2() { // TODO Add two elements to the back and check size and queue in string format. } @Test void testAddFront1() { // TODO Add one element to the front and check size and queue in string format. } @Test void testAddFront2() { // TODO Add two elements to the front and check size and queue in string format. } @Test void testAddFrontRear1() { // TODO Add three elements to the front and/or back then check size and queue in string format. } @Test void testAddFrontRear2() { // TODO Add three elements to the front and/or back then check size and queue in string format. } @Test void testRemoveRear1() { // TODO Remove the element from the back once then check size and queue in string format. } @Test void testRemoveRear2() { // TODO Remove the element from the back twice then check size and queue in string format. } @Test void testRemoveFront1() { // Remove the element from the front once then check size and queue in string format. } @Test void testRemoveFront2() { // TODO Remove the element from the front twice then check size and queue in string format. } @Test void testPeekRear() { // TODO Examine the element from the back then check size and queue in string format. } @Test void testPeekFront() { // TODO Examine the element from the front then check size and queue in string format. } }

** RadixSort.java **

/** * The class defines to sort the integer number in queue. */ public class RadixSort { /** * The number of digit queue. */ public static final int TEN_DIGITS = 10; /** * The max digits in a number. */ public static final int MAX_DIGITS = 4; /** * The method sort the queue using radix sort. * @param master the queue */ public static void sort(Deque master) { @SuppressWarnings("unchecked") Deque[] buckets = new LinkedDeque[TEN_DIGITS]; for (int index = 0; index (); // TODO IMPLEMENT CODE HERE } }

** RadixSortMain.java **

import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintStream; import java.util.Scanner; /** * The main class of the program */ public class RadixSortMain { /** * The main method of the program * @param theArguments the arguments of the program * @throws FileNotFoundException */ public static void main(String[] theArguments) throws FileNotFoundException { Deque master = new LinkedDeque(); readFileIntoDeque("input100.txt", master); RadixSort.sort(master); writeDequeToFile("output100.txt", master); } /** * The method reads all elements from the input file into queue * @param filename the input file * @param queue the queue * @throws FileNotFoundException */ public static void readFileIntoDeque(String filename, Deque queue) throws FileNotFoundException { // TODO IMPLEMENT CODE HERE } /** * The method removes all elements in queue and writes them to output file * @param filename the output file name * @param queue the queue * @throws FileNotFoundException */ public static void writeDequeToFile(String filename, Deque queue) throws FileNotFoundException { // TODO IMPLEMENT CODE HERE } }

image text in transcribed

image text in transcribed

image text in transcribed

I know this is a long assignment but please help. Thank you.

The purpose of this assignment is to get familiar with the deque (double-ended queue) node-based structure along with generic data type. In this assignment, you will involve constructing Java functions that use linked nodes and head and tail references to operate the elements in the list. Moreover, to leverage the usefulness of the structure you designed, we use the deque to apply the radix sort to a list of integer numbers read from a input file. A real-world application of the deque is to store the history of a web browser. The recently visited URLs are added to the front of the deque, and the URL at the back of the deque is removed after some specified number of insertions at the front. Another common application of the deque is to work like a list of undo operations in a software application. We will develop a singly-linked implementation of a double-ended queue. There is an interface Deque that extends from the Queue interface with a new interface called Deque. The class LinkedQueue implements all prototypes in the interface Queue. You are not allowed to modify Queue, Deque, and LinkedQueue. You will develop a new class called LinkedDeque, and this class will extend the provided LinkedQueue class and implements all prototypes in the Deque interface. Please do not add any extra fields or methods. Write the code in the body of each required methods as following: In this assignment, you have to write JUnit tests for all public LinkedDeque operations (including those inherited from LinkedQueue). Your tests should provide complete code coverage (including the toString() method). Think carefully about border cases and exceptional cases as you develop your code and your tests. You will need to take a screenshot that shows all test cases of LinkedDeque passed. Your unit tests should NOT produce any console output. Here is a list of examples of test cases you must have. Your program (RadixSortMain.java) must have the ability to read a text file (public static void readFilelntoDeque(String, Deque )) containing unsorted positive integers entered one per line. I have provided one such file (input100.txt) in the project starter code. It might be useful for you to create other (smaller? larger?) input files to use as you develop and test your code. Your program must use your implementation of radix sort to sort the integers read from the file into sorted order from smallest to largest. Here is the example of how to implement the radix sort (Link). Your program must write the sorted integers to an output text file called "output100.txt" (public static void writeDeque ToFile(String, Deque )), one integer per line. Do not write the output back to the input file, use a separate output file (so that you do not change the input file). The static main method in this class should run the workflow that read integers from an input file (you can hardcode "input100.txt") to a deque, call the sort method from the Radix Sort class, then write back all integers from the deque to an output file (you can hardcode "output100.txt"). You are only allowed to modify the methods in LinkedDeque.java, LinkedDequeTest.java, RadixSort.java, and RadixSortMain.java files as instructed in the class. Any forbidden modification will affect your final score while the instructor using the original files to grade. program does not compile will receive grade of zero. e your code in a class named LinkedDeque, Radix Sort, RadixSortMain, and optionally LinkedDeque Test. Please DO NOT add any extra method or field for classes LinkedDeque, Radix Sort, and Radix SortMain. 1. For the class LinkedDeque: a. Implement the constructor LinkedDeque to initiate necessary properties while creating an instance. We can rely on the constructor of the parent class by using the super magic keyword. b. Implement the method addRear to add an item to the back of the queue. If the item's value is null then the program should throw NullPointerException. c. Implement the method addFront to add an item to the front of the queue. If the item's value is null then the program should throw NullPointerException. d. Implement the method removeRear to remove the item from the back of the queue. If the queue is not empty, we remove the element from the back and return that item (we do not want to lose the connection of the item removed). If the queue is empty then the program should throw EmptyCollectionException (provided). e. Implement the method removeFront to remove the item from the front of the queue. If the queue is not empty, we remove the element from the front and return that item (we do not want to lose the connection of the item removed). If the queue is empty then the program should throw EmptyCollectionException (provided). f. Implement the method peekRear to return the item from the back of the queue if the queue is not empty. Otherwise, (the queue is empty) the program should throw EmptyCollectionException (provided). g. Implement the method peekFront to return the item from the front of the queue if the queue is not empty. Otherwise, (the queue is empty) the program should throw EmptyCollectionException (provided). 2. For the class Radix Sort. We implement a sorting algorithm through the method sort that accepts a double-end queue of integers called master. We sort the numbers from least significant digit (LSD) to the most significant digit (MSD). Inside this method, we create 10 different double-end queues of integers to simulate 10 buckets labeled 0 to 9 to sort the unsorted numbers. Please check out this Youtube video (or HuskyMap video) to understand how it works. 3. For the class RadixSortMain, the method main should remain unchanged: a. Implement the method readFileIntoDeque that accepts a string parameter which is the name of the file consists of unsorted integer numbers. The method will read all those integers into the double-end queue, second parameter that passed into this method. b. Implement the method writeDeque ToFile that accepts a string parameter which is the name of the output file. The method will write all sorted integer numbers from the double-end queue, second parameter that passed into this method. After we run the main method in this class, the program should generate an output file that consists of all integer numbers from the input file sorted. 4. For the class LinkedDequeTest (Extra Credit). a. Follow the instructions in the above table for all test cases testLinkedDeque, extends, testAddRear1, extends, testAddRear2, extends, testAddFront1, extends, testAddFront2, extends, testAddFrontRear1, extends, testAddFrontRear2, extends, testRemoveRear1, extends, testRemoveRear2, extends, testRemoveFront1, extends, testRemoveFront 2 , extends, testPeekRear, and testPeekFront. b. Run this unit testing in your environment (IDE) and take a screenshot that shows how you passed all test cases. c. Please contact me if you like to run the unit testing from the command line or having problem to run unit testing with your environment (IDE). I will try my best to help if you are not using Eclipse. - Be sure your code follows the naming and coding conventions for the class: 1. Instance fields of a class should be named starting with 'my' 2. Parameters to methods should be named starting with 'the' 3. Parameters to methods should be specified as final 4. Javadoc comments should be used for the class as well as the methods of the class 5. You will lose points for each of these things on every assignment if you do not adhere to the rules. 6. See this document for specifics (as well as an example): https://www.oracle.com/java/technologies/javase/codeconventionsintroduction.html Download: - Queue.java (do not modify the content of this file) - Deque.java (do not modify the content of this file) - EmptyCollectionException.java (do not modify the content of this file) - LinkedQueue.java (do not modify the content of this file) - LinkedQueueTest.java (an example of unit testing for LinkedQueue class) - LinkedDeque.java (follow the TODO tags to implement methods) - LinkedDeque Test.java (follow the TODO tags to implement methods) - RadixSort.java (follow the TODO tags to implement methods) - RadixSortMain.java (follow the TODO tags to implement methods) - input100.txt (the sample of input file) - output100.txt (the sample of output file) - readme.txt (example) Submit to Canvas a zip file named assignment05_LASTNAME_FIRS TNAME.zip (all lower cases) that contains the following files: (assignment05_hoang_varik.zip for example) - Here is a list of Java files that you need to submit: 1. LinkedDeque.java 2. LinkedDeque Test.java (optional) 3. Radix Sort.java 4. Radix SortMain.java - A screenshot that shows LinkedDeque passed all test cases using LinkedDeque Test.java (optional) - A readme.txt file that contains the following information 1. Your name 2. An estimate of the amount of time you spent completing the assignment 3. Any problems that exist in the project (if there are not any please state so) 4. Any questions you have for Varik about the assignment Rubric

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

Recommended Textbook for

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions

Question

6. Briefly compare the old and new labor economics.

Answered: 1 week ago