Click here to Skip to main content
15,790,135 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Can anybody tell me what error I have here. Bluej is showing compilation error.

What I have tried:

Java
import java.util.*;
class Queue
{
    public static void main(String[] args)
    {
        Queue a=new LinkedList();
        a.add(8);
        a.add(8);
        a.add(9);

        System.out.println(a);
        System.out.println(a.remove());
    }
}
Posted
Updated 21-Sep-20 0:30am
v2

If your Queue class needs, internally a linked list, then you might write something like
Java
import java.util.*;
class Queue
{
  LinkedList<Integer> m_llist;

  public Queue()
  {
    m_llist = new LinkedList<>();
  }

  public void add(int i)
  {
    m_llist.add(i);
  }

  public static void main(String[] args)
  {
    Queue q = new Queue();
    q.add(8);
    q.add(8);
    q.add(9);
  }
}
 
Share this answer
 
Comments
Member 14829312 21-Sep-20 6:15am    
I don't want linkedlist. I want only queue. My bluej is showing errors in add and remove.

import java.util.*;
class Queue
{
public static void main(String[] args)
{
Queue a=new Queue();
a.add(8);
a.add(8);
a.add(9);

System.out.println(a);
System.out.println(a.remove());
}
}


Help me. Correct it and resend me.
CPallini 21-Sep-20 6:19am    
You have to implement both the Queue constructor and the add method (moreover you have to store, in the container you like, the Integers received by the add method).
Member 14829312 21-Sep-20 6:23am    
Show me edited source code.
Richard MacCutchan 21-Sep-20 9:44am    
+5 for a detailed implementation.
Java
Queue a=new LinkedList();

You cannot assign a LinkedList to an object of type Queue. There is no relationship between them.
 
Share this answer
 
Comments
CPallini 21-Sep-20 5:28am    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900