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

I need help with this Java Data Structures assignment. Thanks Runtime Interface

ID: 3805321 • Letter: I

Question

I need help with this Java Data Structures assignment. Thanks

Runtime Interface Methods

public interface RunTimeInterface
{
   public static enum TimeUnits {Seconds, MilliSeconds, MicroSeconds, NanoSeconds};
   public static enum MemoryUnits {Bytes, KiloBytes, MegaBytes};
   public TimeUnits getTimeUnits();
   public void setTimeUnits(TimeUnits timeUnits);
   public MemoryUnits getMemoryUnits();
   public void setMemoryUnits(MemoryUnits memoryUnits);
   public double getLastRunTime();
   public double getLastMemoryUsage();
   public double[] getRunTimes();
   public double[] getMemoryUsages();
   public void resetRunTimes();
   public void addRuntime(long runTime);
   public double getAverageRunTime();
   public double getAverageMemoryUsage();
  
}

Queue Interface

Stack Interface

Iterable Interface

Iterator Interface

Node Class

Driver Interface

Details 1. RunTime Class You will be expanding the functionality of the RunTime class to implement the expanded RunTime Interface The interface may be downloaded from RunTimeInterface.iava 2. Array Based Queue class You will write the ArrayBasedgueue.java class which will implement the Queue Interface The interface may be downloaded from QueueInterface.iava. Please note that Queue Interface extends the Iterable Interface. See the Information On The Iterable Interface below 3. Linked Queue Class You will write the Linkedgueue. java class which will implement the Queue Interface. The interface may be downloaded from QueueInterfaceiava. Please note that Queue Interface extends the Iterable Interface. See the Information On The Iterable Interface below. Also note that the Linked Queue Class should be a Doubly Linked Queue. 4. Array Based Stack Class You will write the ArrayBasedstack. java class which will implement the Stack Interface. The interface may be downloaded from StackInterface.iava. Please note that Stack Interface extends the Iterable Interface See the Information On The Iterable Interface below.

Explanation / Answer

import java.util.*;
class Node

{

    protected int data;
    protected Node link;

   public Node()

    {

        link = null;

        data = 0;

    }  

    /* Constructor */

    public Node(int d,Node n)

    {

        data = d;

        link = n;

    }  

    /* Function to set link to next Node */

    public void setLink(Node n)

    {

        link = n;

    }  

    /* Function to set data to current Node */

    public void setData(int d)

    {

        data = d;

    }  

    /* Function to get link to next node */

    public Node getLink()

    {

        return link;

    }  

    /* Function to get data from current Node */

    public int getData()

    {

        return data;

    }

}

/* Class linkedQueue */

class linkedQueue

{

    protected Node front, rear;

    public int size;

    /* Constructor */

    public linkedQueue()

    {

        front = null;

        rear = null;

        size = 0;

    }  

    /* Function to check if queue is empty */

    public boolean isEmpty()

    {

        return front == null;

    }  

    /* Function to get the size of the queue */

    public int getSize()

    {

        return size;

    }  

    /* Function to insert an element to the queue */

    public void insert(int data)

    {

        Node nptr = new Node(data, null);

        if (rear == null)

        {

            front = nptr;

            rear = nptr;

        }

        else

        {

            rear.setLink(nptr);

            rear = rear.getLink();

        }

        size++ ;

    }  

    public int remove()

    {

        if (isEmpty() )

            throw new NoSuchElementException("Underflow Exception");

        Node ptr = front;

        front = ptr.getLink();      

        if (front == null)

            rear = null;

        size-- ;      

        return ptr.getData();

    }  
    public int peek()

    {

        if (isEmpty() )

            throw new NoSuchElementException("Underflow Exception");

        return front.getData();

    }  

    public void display()

    {

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

        if (size == 0)

        {

            System.out.print("Empty ");

            return ;

        }

        Node ptr = front;

        while (ptr != rear.getLink() )

        {

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

            ptr = ptr.getLink();

        }

        System.out.println();      

    }

}

public class LinkedQueueImplement

{  

    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. insert");

            System.out.println("2. remove");

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

            System.out.println("4. check empty");
             int choice = scan.nextInt();

            switch (choice)

            {

            case 1 :

                System.out.println("Enter integer element to insert");

                lq.insert( scan.nextInt() );

                break;                       

            case 2 :

                try

                {

                    System.out.println("Removed Element = "+ lq.remove());

                }

                catch (Exception e)

                {

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

                }  

                break;                       

            case 3 :

                try

                {

                    System.out.println("Peek Element = "+ lq.peek());

                }

                catch (Exception e)

                {

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

                }

                break;                       

            case 4 :
                System.out.println("Empty status = "+ lq.isEmpty());
                break;
                 default :

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

                break;
            }              

            /* display queue */      

            lq.display();

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

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

        } while (ch == 'Y'|| ch == 'y');                                                          

    }

}