{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

AQueueDriver - System.out.println"The value"...

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 AQueueDriver { public static void main(String[] args){ AQueue<Integer> intQueue = new AQueue<Integer>(5) A 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() intQueue.enqueue(temp)
Background image of page 1

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

View Full Document Right 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: System.out.println("The value "+temp+" has been enqueued.") } else{ System.out.println("Invalid input. ..must be an integer!") in.next() } break case 'd': try{ System.out.println("The value "+intQueue.dequeue()+" has been dequeued.") } catch(AQueue.MyException e){ System.out.println("Invalid Operation: The Queue is empty") } break case 'e': if(intQueue.isEmpty()) System.out.println("Empty") else System.out.println("Not Empty") break case 'p': intQueue.printArray() break case 'q': while(!intQueue.isEmpty()){ System.out.println("The value "+intQueue.dequeue()+" has been dequeued.") Sheet1 Page 2 } break default: System.out.println("Error enter a valid menu choice!") } } } }...
View Full Document

{[ snackBarMessage ]}