Please help:) Implement the following operation in Queue using array based implementation in java You are required to create multiple classes and methods to perform the following with queue. 1.insert the following letters into the queue using keyboard input. {a, b, c, d, e, f, g, h, i} 2.Remove some of the letters from the queue. 3.Insert some more letters into the queue 4.Print the remaining letters in the queue in order 5.write a method to check whether the queue is empty. 6.write a method to check whether the queue is full.

At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get our expert's

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this and thousands of other questions.

A community for students.

Please help:) Implement the following operation in Queue using array based implementation in java You are required to create multiple classes and methods to perform the following with queue. 1.insert the following letters into the queue using keyboard input. {a, b, c, d, e, f, g, h, i} 2.Remove some of the letters from the queue. 3.Insert some more letters into the queue 4.Print the remaining letters in the queue in order 5.write a method to check whether the queue is empty. 6.write a method to check whether the queue is full.

Computer Science
See more answers at brainly.com
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this and thousands of other questions

7.Write a method to print the number of elements in the queue.
import java.io.*; class Queue3 { private int maxSize; private char[] queueArr; private int front; private int rear; private int nItems; public Queue3(int s) { maxSize=s; queueArr=new char[maxSize]; front=0; rear=-1; nItems=0; } public void insert(char letter) { if(rear==maxSize-1) rear=-1; queueArr[++rear]=letter; nItems++; } public char remove() { char temp=queueArr[front++]; if(front==maxSize) front=0; nItems--; return temp; } public char peekFront() { return queueArr[front]; } public boolean isEmpty() { return (nItems==0); } public boolean isFull() { return (nItems==maxSize); } public int size() { return nItems; } } class QueueApp3 { public static void main(String [] args) throws IOException { BufferedReader keyboard = new BufferedReader (new InputStreamReader(System.in)); int a; int b; char c; int d; System.out.print("Enter the size of the array:"); a=Integer.parseInt(keyboard.readLine()); Queue3 theQueue=new Queue3(a); System.out.print("Enter the number of items to be inserted:"); b=Integer.parseInt(keyboard.readLine()); for(int i=1;i<=b;i++) { System.out.print("Enter the item:"); c=(char)keyboard.read(); theQueue.insert(c); } System.out.print("Enter the number of items to be removed:"); d=Integer.parseInt(keyboard.readLine()); for(int k=1;k<=d;k++) { theQueue.remove(); } System.out.print("Enter the number of items to be inserted:"); b=Integer.parseInt(keyboard.readLine()); for(int i=1;i<=b;i++) { System.out.print("Enter the item:"); c=(char)keyboard.read(); theQueue.insert(c); } while(!theQueue.isEmpty()) { char n=theQueue.remove(); System.out.print(n); System.out.print(" "); } System.out.println(" "); } }
My output has to be Enter the size of the array: 20 Enter the number of items to be added: 9 Enter the item: a Enter the item: b Enter the item: c Enter the item: d Enter the item: e Enter the item: f Enter the item: g Enter the item: h Enter the item: i Enter the number of items to be removed: 4 Enter the number of items to be added: 6 Enter the item: j Enter the item: k Enter the item: l Enter the item: m Enter the item: n Enter the item: o e f g h i j k l m n o

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

@KonradZuse. if u dnt mind can u please help me?
Seems like your issue is removing, re-adding, etc. You also ask for an array size, then number size.
ya
If u dnt mind can u pls tell me whr I have made the mistake in my code?
your second class. Edit it... Instead of doing enter total, then enter total amount, then enter each #, then remove, then enter, try to fix that. Ask them how many numbers, then what they are. Next I would have a method to remove data randomly. Not at any set point. So you might need to say, do you want to enter, or remove. Also not sure if the additions /removals arejust at the end.
Sorry. Actually they want it that way. that is y I did so. bt I am nt getting that output.:(
They want you to add, remove, then add again? It seemed like add, and remove whenever.... Right not yout code asks for 20 spots, then 9 sports. IT then deletes the first 4 spots as you mentioned above, then added in the new letters at the end. Change where the letters are being deleted I guess if it's at the end and not random.
in a queue the letters will be deleted from front right? What i am nt getting is c=(char)keyboard.read(); theQueue.insert(c);. it is not looping.
it looks like it's looping to me... I guess you do the front, since tha'ts a queue but you cand elete anywhere...
ya. bt hw can we delete from anywhere. Really sorry for troubling u. I dnt get t. In fact I tried evrywhere chckng why it is nt looping. bt I was nt unable to find any solution. Please help
IT IS looping...
System.out.print("Enter the number of items to be inserted:"); b=Integer.parseInt(keyboard.readLine()); for(int i=1;i<=b;i++) { System.out.print("Enter the item:"); c=(char)keyboard.read(); theQueue.insert(c); }
Enter the item: j Enter the item: k Enter the item: l Enter the item: m Enter the item: n Enter the item: o e f g h i j k l m n o
but y it is not looping for me:(
it is, why are you saying it isn't...? Am I mising something? It does everything it should imo.
Enter the size of the array: 20 Enter the number of items to be added: 9 Enter the item: a Enter the item: Enter the item: Enter the item: Enter the item: Enter the item: Enter the item: Enter the item: Enter the item: Enter the number of items to be removed: 2 Enter the number of items to be added: 6 Enter the item: j Enter the item: Enter the item: Enter the item: Enter the item: nEnter the item: This is the output I am getting.:(
hmm Let me take a look at the code in my IDE later for you.
That while loop makes no sense at the bottom.
The problem you are having is a result of your "keyboard.read()". The first time through it asks you to enter the item you type "a", then you hit enter, what gets passed to your insert function is 'a'. The next time through you type "b", then hit enter, what gets passed to your insert function is '\r'. The next time through you type "c", then hit enter, what gets passed to your insert function is '\n'. This can be fixed by changing your keyboard from a BufferedReader to a Scanner, also, since your method can throw an exception, you need to handle it with a try/catch block.
http://pastebin.com/wz7crjvD
Thanxxxx a lot @eSpex nd thax to u too @KonradZuse
I kept looking at that BufferReader but wasn't sure if it was another way to do it. What is /r and /n?
\r is the return key and \n is the newline character.

Not the answer you are looking for?

Search for more explanations.

Ask your own question