Question: need help with this in java Write a queue client, LineNum, that takes an integer command line argument n and prints the nth string from

need help with this in java Write a queue client, "LineNum," that takes an integer command line argument n and prints the nth string from the first string found on standard input. [MO6.2]
Please note that you should use an object of the Queue class given in the textbook (program 4.3.6) to implement it. You should add the strings inputted by the user to a queue using the enqueue method. After the user has finished inputting strings (and they've been added to the queue) you should remove "n" strings from the queue by calling the dequeue method (which would also return the string that is removed from the queue) n times. The string that is returned by the dequeue method when it is called the nth time should then be printed out.
Sample runs would be as follows.
>java LineNum 2
apple
save
that
is
too
me
2 from the first is save
>java LineNum 3
this
is
not
a
shorter
version
3 from the first is not the code referenced in the question is public class Queue
{
private Node first;
private Node last;
private class Node {
private Item item;
private Node next;
}
public boolean isEmpty(){
return first == null;
}
public void enqueue(Item item){
Node oldlast = last;
last = new Node();
last.item = item;
last.next = null;
if (isEmpty()) first = last;
else oldlast.next = last;
}
public Item dequeue(){
if (isEmpty()) throw new NoSuchElementException("Queue underflow");
Item item = first.item;
first = first.next;
n--;
if (isEmpty()) last = null; // to avoid loitering
return item;
}
public static void main(String[] args){
Queue queue = new Queue();
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!