Question

In: Computer Science

Using the Queue ADT: Create a program that uses a Queue. Your program should ask the...

Using the Queue ADT:

Create a program that uses a Queue. Your program should ask the user to input a few lines of text and then outputs strings in same order of entry. (use of the library ArrayDeque)

In Java please.

Solutions

Expert Solution

ANSWER:--

GIVEN THAT:--

CODE:

// import ArrayDequeue
import java.util.*;

// extends abstract queue
public class Queue extends adtqueue {
  
   Deque<Character> deque = new ArrayDeque<Character>(10);

   public static void main(String[] args) {

//       making instance of Queue
       Queue q= new Queue();
      
//      
System.out.println();
      
       System.out.println("Operation on String : WASHINGTON");
      
       System.out.println();
      
       String test="WASHINGTON";
      
       System.out.print("String entered into Queue : WASHINGTON");
       q.enqueue('W');
       q.enqueue('A');
       q.enqueue('S');
       q.enqueue('H');
       q.enqueue('I');
       q.enqueue('N');
       q.enqueue('G');
       q.enqueue('T');
       q.enqueue('O');
       q.enqueue('N');
      
       System.out.println();
       System.out.println();
      
       System.out.print("String Dequeueed from Queue by one by one chars : ");
      
       while(!q.isEmpty()) {
          
           System.out.print(q.dequeue()+" ");
          
       }
      
       System.out.println();
       System.out.println();
      
       System.out.println("Yes! String is in Same order");
          
   }
  
//   return is Empty
   boolean isEmpty() {
      
       return deque.isEmpty();
      
   }
  

   @Override
   void enqueue(char i) {
      
       deque.add(i);
      
   }

   @Override
   char dequeue() {
      
       char c=deque.remove();
      
       return c;
   }

   @Override
   char top() {
      
       char c=deque.peekFirst();
      
       return 0;
   }
  
  
}


// Abstract Queue class

abstract class adtqueue{

   abstract void enqueue(char i);
  
   abstract char dequeue();
  
   abstract char top();
  
}

SAMPLE OUTPUT:


Related Solutions

Using the Stack ADT: Create a program that uses a stack. Your program should ask the...
Using the Stack ADT: Create a program that uses a stack. Your program should ask the user to input a few lines of text and then outputs strings in reverse order of entry. (Optional) Create a similar program that uses a stack. Your new program should ask the user to input a line of text and then it should print out the line of text in reverse. To do this your application should use a stack of Character. In Java...
2. Using the Stack ADT: Create a program that uses a stack. Your program should ask...
2. Using the Stack ADT: Create a program that uses a stack. Your program should ask the user to input a few lines of text and then outputs strings in reverse order of entry. In Java please.
Create an ADT class that creates a friend contact list. The program should be able to...
Create an ADT class that creates a friend contact list. The program should be able to add, remove and view the contacts. In C++
PYTHON- create a queue class that uses a LINKEDLIST in order to store data. this queue...
PYTHON- create a queue class that uses a LINKEDLIST in order to store data. this queue will call on a linkedlist class class Queue: def __init__(self): self.items = LinkedList() #has to be O(1) def enqueue(self, item): #has to be O(1) def dequeue(self): def is_empty(self): def __len__(self):
Using a single queue (linkedQueue), re-implement the concept of Stack ADT, what is the complexity of...
Using a single queue (linkedQueue), re-implement the concept of Stack ADT, what is the complexity of the method push, pop, top, isEmpty, and size. You should not use any extra data structure. Related codes: public interface Stack<E> { int size( ); boolean isEmpty( ); void push(E e); E top( ); E pop( ); } public class LinkedStack<E> implements Stack<E> { private SinglyLinkedList<E> list = new SinglyLinkedList<>( );    public LinkedStack( ) { }    public int size( ) { return...
In C++, Implement the queue ADT with a singly linked list
In C++, Implement the queue ADT with a singly linked list
Create a Netbeans project called LineNumbers The program should do the following: –Ask the user for...
Create a Netbeans project called LineNumbers The program should do the following: –Ask the user for how many lines of text they wish to enter –Declare and initialize an array of Strings to hold the user’s input –Use a while loop to prompt for and read the Strings (lines of text) from the user at the command line. Typically, this would be a 'for' loop since we know the number of times to execute the loop based upon the number...
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create...
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create 2 threads that will act as counters. One thread should count down from 5 to 0. Once that thread reaches 0, then a second thread should be used to count up to 20.
Using (C programming language) Create a health monitoring program, that will ask user for their name,...
Using (C programming language) Create a health monitoring program, that will ask user for their name, age, gender, weight, height and other health related questions like blood pressure and etc. Based on the provided information, program will tell user BMI, blood pressure numbers if they fall in healthy range or not and etc. Suggestions can be made as what should be calorie intake per day and the amount of exercise based on user input data. User should be able to...
Introduction to Java Programing Using Loop Create a simple calculator program using loop Ask user to...
Introduction to Java Programing Using Loop Create a simple calculator program using loop Ask user to input two numbers using scanner class Print the instruction of the menu for the calculator program Ask user to press 0 to Quit Ask user to press 1 to Add Ask user to press 2 to Substract Ask user to press 3 to Multiply Ask user to press 4 to Divide Perform correct calcuation based on user inputs and print the result Print error...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT