Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Make sure that your code contains comments explaining your code. Use Chapter 14

ID: 3862105 • Letter: M

Question

Make sure that your code contains comments explaining your code.

Use Chapter 14 as a guide to complete the following part 1 and 2 below. You can delete references to the jsjf exceptions (you may also need to modify the code as well in parts that reference it).

Part 1. Complete the implementation of the LinkedQueue class presented in this chapter. Specifically, complete the implementation of the first, isEmpty, size and toString Methods. Also create a driver class (main) to test the functionality of the methods of your program. ToString should print all the elements in the Queue.

Part 2. Complete the implementation do the CircularArrayQueue class described in chapter 14, including all methods. Also create a driver class (main) to test the functionality of the methods of your program.

Explanation / Answer

For part1 implementation, Here I am providing the tested answer. For part 2 Question more information needed, and as per the chegg guidelines I am answering the first part only.

class linkedQueue

{

    protected Node first, last;

    public int size;

    public linkedQueue()

    {

        first = null;

        last = null;

        size = 0;

    }  
  
    public boolean isEmpty()

    {

        return first == null;

    }  

    public int getSize()

    {

        return size;

    }  

    public int first()

    {

        if (isEmpty() )

            throw new NoSuchElementException("Underflow Exception");

        return first.getData();

    }  

    public void toString()

    {

        System.out.println(" Queue = ");

        if (size == 0)

        {

            System.out.println("Empty ");

            return ;

        }

        Node p = first;

        while (p != last.getLink() )

        {

            System.out.print(p.getData()+" ");

            p = ptr.getLink();

        }

        System.out.println();      

    }

}

public class LinkedQueueimplementation

{  

    public static void main(String[] args)

    {

        Scanner scan = new Scanner(System.in);
   
        linkedQueue lq = new linkedQueue();          

        System.out.println("Linked Queue Test ");

        char ch;      

        do

        {

            System.out.println(" Queue Operations");

            System.out.println("1. first element");

            System.out.println("2. check empty");

            System.out.println("3. size");

        System.out.println("4. Display All Elements(toString)");

            int choice = scan.nextInt();

            switch (choice)

            {

            case 1 :

                try

                {

                    System.out.println("First Element = "+ lq.first());

                }

                catch (Exception e)

                {

                    System.out.println("Error : " + e.getMessage());

                }

                break;                       

            case 2 :

                System.out.println("Empty status = "+ lq.isEmpty());

                break;

           case 3 :

                System.out.println("Size = "+ lq.getSize());

                break;
   case 4 :
  
       lq.display();
      
       break;

            default :

                System.out.println("Wrong Entry ");

                break;

            }              
       
            System.out.println(" Do you want to continue (Type y or n) ");

            ch = scan.next().charAt(0);          

        } while (ch == 'Y');                                                          

    }

}

There are 4 methods. The class LinkedQueueimplementation tests the given four functionalities by user choice.

Hence the solution provided.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote