Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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. MO
Please note that you should use an object of the Queue class given in the textbook program 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
apple
save
that
is
too
me
from the first is save
java LineNum
this
is
not
a
shorter
version
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 enqueueItem 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 NoSuchElementExceptionQueue underflow";
Item item first.item;
first first.next;
n;
if isEmpty last null; to avoid loitering
return item;
public static void mainString args
Queue queue new Queue;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started