Question: This is a java file and queue question. I want to read a txt file which includes enqueue 1 dequeue 2 peek 3 size 4
This is a java file and queue question. I want to read a txt file which includes
"enqueue 1
dequeue 2
peek 3
size 4" something like this. When there is "enqueue", enqueue into the queue. And "dequeue", "peek" and "size". And I have a project can show you but it's broken. Please help me out.
public class queue { private String fileName = ""; private Queue
{ System.out.println("Invalid Argument"); } catch(IllegalStateException i)
{ System.out.println("Illegal State"); } } else if (newString.equals("peek")) { try { while(parse.hasNext() )
{ System.out.println(queue.peek()); } } catch(NumberFormatException n) { System.out.println("Invalid Argument"); } catch(IllegalStateException i) { System.out.println("Illegal State"); } } else if (newString.equals("dequeue")) { try { while(parse.hasNext()) { queue.dequeue(); } } catch(NumberFormatException n) { System.out.println("Invalid Argument"); } catch(IllegalStateException i) { System.out.println("Illegal State"); } } else if (newString.equals("size")) { try { while(parse.hasNext()) { System.out.println(queue.size()); } } catch(NumberFormatException n) { System.out.println("Invalid Argument"); } catch(IllegalStateException i) { System.out.println("Illegal State"); } } else { System.out.println("Invalid Command"); } parse.close(); } in.close(); }
public void printStructure() { while (!queue.isEmpty()) { System.out.println(queue.peek()); //System.out.println(queue.size()); queue.dequeue(); } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
