Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

As instructed, Please modify the program (Add a new method) to the existing program * Java Program to Implement Queue / import java.util.*; * Class

As instructed, Please modify the program (Add a new method) to the existing program image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
* Java Program to Implement Queue / import java.util.*; * Class arrayQueue */ class arrayQueue protected int Queue[]; protected int front, rear, size, len; /* Function to check if queue is empty */ public boolean isEmpty() returfront=1; / Function to check if queue is full */ public boolean isFullo retumfront=0&&rear=size1; /* Function to get the size of the queue */ public int getSize() return len : /* Function to check the front element of the queue *l public int peek() is if if (isEmpty()) throw new NoSuchElementException("Underflow Exception"); return Queue[front]; / Function to insert an element to the queue */ public void insert(int i) 1 " Class Queuelmplement */ public class Queuelmplement public static void main(String[] args) 11 Scanner scan= new Scanner(System.in); System.out.printin("Array Queue Testin"): System.out.println("Enter Size of Integer Queue "); int n= scan.nextint(0); /* creating object of class arrayQueue */ arrayQueue q= new arrayQueue (n); /* Perform Queue Operations */ char ch: do! System.out.println(" Queue Operations"); System.out,printin("1, insert"); System.out,println("2, remove"); System.out,println("3, peek"); System.out,println("4, check empty"); System.out.println("5. check full"); System.out.println("6. size"); int choice = scan nextInt): switch (choice) i case 1 : System.out.println("Enter integer element to insert"): try i q.insert ( scan.nextint(0); catch(Exception e) 1 System.out.println("Error: " +e.getMessage()): break; case 2 : try i System.out.println("Removed Element = "+q_remove()); ( catch(Exception e) i System.out.println("Error: " +e.getMessage()): break; case 3 : try System.out.println("Peek Element = "+q.peek()); catch(Exception e) System.out.println("Error : "+e.getMessage()); break; case 4: System.out.println("Empty status = "+q. isEmpty()); break; case 5 : System.out.println("Full status = "+q.isFull()); break; case 6: System.out.println("Size = "+ q.getSize()); break; default : System.out.println("Wrong Entry "); break; /* display Queue */ q.display(); System.out.println("'nDo you want to continue (Type y or n ) "); ch = scan.next().charAt (0); i while ( ch =Ych=y); 11

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Michael V. Mannino

4th Edition

0615231047, 978-0615231044

More Books

Students also viewed these Databases questions

Question

10:16 AM Sun Jan 29 Answered: 1 week ago

Answered: 1 week ago