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("The value "+temp+" has been enqueued.") } else System.out.println("Invalid input. ..must be an integer!") break case 'd': try{ System.out.println("The value "+intQueue.dequeue()+" has been dequeued.") } catch(LQueue.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 'q': while(!intQueue.isEmpty()){ System.out.println("The value "+intQueue.dequeue()+" has been dequeued.") } break default: System.out.println("Error enter a valid menu choice!") } 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