LQueueDriver

LQueueDriver - intQueue.enqueue(temp)...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 import java.util.* public class LQueueDriver { public static void main(String[] args){ LQueue<Integer> intQueue = new LQueue<Integer>() L System.out.println("Choose one of the following operations:") System.out.println("-enqueue/add (enter letter a)") System.out.println("-dequeue/delete (enter letter d)") System.out.println("-check if the list is empty (enter letter e)") System.out.println("-quit (enter letter q)") char userInput = ' ' int temp Scanner in = new Scanner(System.in) S while(userInput != 'q'){ System.out.print("Enter a menu option: ") userInput = in.next().charAt(0) u switch(userInput){ case 'a': System.out.print("Enter the value to add: ") if(in.hasNextInt()){ temp = in.nextInt()
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: intQueue.enqueue(temp) System.out.println(&quot;The value &quot;+temp+&quot; has been enqueued.&quot;) } else System.out.println(&quot;Invalid input. ..must be an integer!&quot;) break case 'd': try{ System.out.println(&quot;The value &quot;+intQueue.dequeue()+&quot; has been dequeued.&quot;) } catch(LQueue.MyException e){ System.out.println(&quot;Invalid Operation: The Queue is empty&quot;) } break case 'e': if(intQueue.isEmpty()) System.out.println(&quot;Empty&quot;) else System.out.println(&quot;Not Empty&quot;) break case 'q': while(!intQueue.isEmpty()){ System.out.println(&quot;The value &quot;+intQueue.dequeue()+&quot; has been dequeued.&quot;) } break default: System.out.println(&quot;Error enter a valid menu choice!&quot;) } Sheet1 Page 2 } } }...
View Full Document

Page1 / 2

LQueueDriver - intQueue.enqueue(temp)...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online