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

Create a program named queue.java that implements a queue of monster class eleme

ID: 666482 • Letter: C

Question

Create a program named queue.java that implements a queue of monster class elements. The class is below:

class MonsterInfo
{
   private String Name;
   private String Species;
   private int HitPoints;
   // add two more of your own attributes

   // add a constructor with parameters for the attributes

   // add get and set methods to access all attributes
}

Main program methods should include Enqueue, Dequeue, Peek, and IsEmpty.

The main program should begin by adding at least 4 monsters to the queue, then have the following menu options:

Welcome to the Monster Queue!
1 = Dequeue the monster at the front of the queue
2 = Enqueue a new monster
3 = List all the Monsters in the Queue
4 = Run for the Exit!
Your Choice:
1
You just dequeued an Orc named Dork with 100 hit points.

Explanation / Answer

working java code

public class MonsterInfo {

   private String Name;
   private String Species;
   private int HitPoints;
    private Node front;
    private Node back;

    public MonsterInfo() {
            front = null;
            back = null;
            HitPoints = 0;
    }

    public void enqueue(Object x) {
        if( isEmpty() )
            back = front = new Node(x);
        else
            back = back.next = new Node(x);
        HitPoints++;
    }

    public Object dequeue() {
        Object x;
        if( isEmpty() ) { System.out.println("nothing to dequeue. queue empty."); }
        x = front.data;
        HitPoints--;
        return x;
    }

    public boolean isEmpty() {
        if(HitPoints == 0)
            return true;
        else
            return false;
    }

    public void printQueue() {
        if ( isEmpty() )
            System.out.println("empty queue");
        else {
            Node temp = front;
            while(temp != null) {
                System.out.println(temp);
                temp = temp.next;
            }
        }
    }

}

public static void main(String[] args) {
    String a = "dd";
    String b = "cc";
    String c = "Pen";

    myQueue q = new myQueue();

    q.enqueue(a);
    q.enqueue(b);
    q.enqueue(c);

    System.out.println(" ");

    q.printQueue();
}

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