Question

See all photos + Add to a ♡ Search Edit & Create Share . Benny the Barber owns a one-chair shop. They told Benny that custome

class BarberShopTest{ @Test void testAddCustomer() { BarberShop barberShop = new BarberShop(Benny the Barber); Customer cus

USE JAVA PROGRAMMING LANGUAGE

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// Assuming Customer class is defined
// LinkedQueue.java : Java program to create a Queue using LinkedList

import java.util.NoSuchElementException;

public class LinkedQueue {
  
   // inner class Node representing the Node of the LinkedQueue where data contains Customer and next is the Node to the next Customer
   private class Node
   {
       Customer data;
       Node next;
      
       public Node(Customer inData)
       {
           data = inData;
           next = null;
       }
      
       public Customer toString()
       {
           return(data.toString());
       }
   }
  
   private Node head; // start of queue
   private Node tail; // end of queue
  
   // constructor to create an empty Queue
   public LinkedQueue()
   {
       head = null;
       tail = null;
   }
  
   // method to insert the Customer at the end of the queue
   public void enqueue(Customer data)
   {
       if(data != null)
       {
           Node node = new Node(data);
           if(isEmpty())
           {
               head = node;
               tail = node;
           }else
           {
               tail.next =node;
               tail = node;
           }
       }
   }

   // method to remove and return the Customer at the front of the Queue
   public Customer dequeue() throws NoSuchElementException
   {
       if(!isEmpty())
       {
           Customer item = head.data;
           head = head.next;
           if(head == null)
               tail = null;
           return item;
       }
      
       throw new NoSuchElementException();
   }
  
   // method to return the Customer at the front of the queue
   public Customer getFront() throws NoSuchElementException
   {
       if(!isEmpty())
       {
           return head.data;
       }
      
       throw new NoSuchElementException();
   }
  
   // method to return the String representation of the queue
   public String toString()
   {
       String queueStr = "";
       Node curr = head;
       while(curr != null)
       {
           queueStr += (curr.toString()+"\n");
           curr = curr.next;
       }
      
       return queueStr;
   }
  
   // method to return true if the queue is empty else false
   public boolean isEmpty(){return (head == null);}  

}

//end of LinkedQueue.java

Add a comment
Know the answer?
Add Answer to:
USE JAVA PROGRAMMING LANGUAGE See all photos + Add to a ♡ Search Edit & Create...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT