Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6472839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:23:38+00:00 2026-05-25T06:23:38+00:00

Queue12 is an interface, QueueImp12 is an implementation of Queue12. So i’m trying to

  • 0

Queue12 is an interface, QueueImp12 is an implementation of Queue12. So i’m trying to test my QueueImp12 but when i run it(it compiles) in eclipse my output gets terminated in console. I believe I created ringBuffer correctly. If my test looks fine, then something must be wrong with my implementation or eclipse. Thanks

import java.util.NoSuchElementException;


public class QueueImpl12<T> implements Queue12<T> 
{

private int _size, _backIdx, _frontIdx;
private static final int _defaultCapacity = 128;
private T[] _ringBuffer;



public QueueImpl12(int capacity)
{
    _ringBuffer = (T[]) new Object[capacity];
    clear();    
}


public QueueImpl12()
{
    _ringBuffer = (T[]) new Object[_defaultCapacity];
    clear();
}

private int wrapIdx(int index)
{

    return index % capacity();
}



public void clear() 
{
    _backIdx = 0;
    _frontIdx = 0;
    _size = 0;

}

@Override
public int capacity() 
{
    // TODO Auto-generated method stub
    return _ringBuffer.length;
}

@Override
public int size() 
{
    // TODO Auto-generated method stub
    return _size;
}

@Override
public boolean enqueue(T o) 
{
    //add o to back of queue


    if(_ringBuffer.length == _size)
    {
        return false;
    }


       _ringBuffer[_backIdx] = o;
        _backIdx = wrapIdx(_backIdx + 1 );
        _size++;





    return true;
}

@Override
public T dequeue()
{
    if(_size == 0)  //empty list
    {
        throw new NoSuchElementException();
    }

    T tempObj = _ringBuffer[_frontIdx];     //store frontIdx object
    _ringBuffer[_frontIdx] = null;          
    _frontIdx++;



    _size--;
    return tempObj;
}

@Override
public T peek() 
{

    return _ringBuffer[_frontIdx];
}

}




public class P3test  
{
public static<T> void main(String[] args) 
{
    final Queue12<T> ringBuffer = new QueueImpl12<T>();
    T o = (T) new String("this");
    ringBuffer.enqueue(o); //add element to the back
    ringBuffer.dequeue();  //remove/return element in the front

}
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:23:39+00:00Added an answer on May 25, 2026 at 6:23 am

    That ‘terminated’ you have been seeing lately is the expected behavior when your program finishes.

    Put some System.outs or asserts to verify that your code runs (here it runs, with some awful cast warnings, but runs)

    final Queue12<T> ringBuffer = new QueueImpl12<T>();
    T o = (T) new String("this");
    ringBuffer.enqueue(o); //add element to the back
    System.out.println(ringBuffer.peek());//this should print 'this' in the console\
    //assertEquals('this', ringBuffer.peek());
    ringBuffer.dequeue();  //remove/return element in the front
    

    Learn how to use generics and tests. And don’t put generic argument in main function, is is useless there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to document the private variable in phpdoc but its not documenting.
Hi I am trying append a simple element to a lisp list. (append queue1
I am trying to set up my workflow with MQ as described in the
In my build configuration I have multiple project queues: Queue1, Queue2, ... Queue(N) I
I have few tables that have the same structure (e.g. Queue1, Queue2, etc.). I
Is there any inherent advantage when using multiple workers to process pieces of procedural
We have a project where we want to link 2 enterprise systems together using
I have a list of objects and I would like to access the objects
I am beginning to use LINQ in general (so far toXML and toSQL). I've
Is it valid to use 2 different CloudQueue objects to manipulate the same queue?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.