-3

So I've created a Deque interface, but I'm not sure how I go about instantiating my Deque, I thought to use ArrayDeque, but I believe that ArrayDeque is another Interface, and I'm trying to use my own Interface.

public interface DequeInterface {
 public void addFront(Object o);
 public void addRead(Object o);
 public Object removeFront();
 public Object removeRear();

}

public class Deque implements DequeInterface {

}
Aman Kakkar
  • 51
  • 1
  • 8
  • I also need to instantiate it with a size of 100 – Aman Kakkar Jan 20 '16 at 01:25
  • 1
    whats the question though? – Sleiman Jneidi Jan 20 '16 at 01:26
  • 1
    This code won't compile because your `Deque` does not (yet) implement `DequeInterface.` – Matt Ball Jan 20 '16 at 01:29
  • My question overall is how do I go about making the methods in the interface concrete, I'm not sure how to move further from what I've already got. – Aman Kakkar Jan 20 '16 at 01:31
  • 2
    Although what you're trying to do is generic, you haven't provided enough guidelines so that it is clear what the "correct" answer is. It would be helpful if you provided clear requirements and show us what you've tried so far :) – Frank Bryce Jan 20 '16 at 01:55
  • 1
    You "making the methods in the interface concrete" by actually implementing them, i.e. writing them with code to get the behavior you want. – Andreas Jan 20 '16 at 02:00
  • That is basically all I have so far, the initial question is to create a Java class Deque which implements a deque with the capacity to hold 100 object, and it should implement the DequeInterface interface. Thats all the question is, I've tried looking around, but couldn't find any help. Sorry I can't elaborate any further. – Aman Kakkar Jan 20 '16 at 02:00
  • Do you understand how a Deque works when the backing store is an array (as opposed to, say, a linked list)? – Andreas Jan 20 '16 at 02:02
  • You may be better off at this stage contacting your instructor as your question is awfully broad. – Hovercraft Full Of Eels Jan 20 '16 at 02:02
  • @Andreas I can easily implement them, but I need a Deque object to actually do all the adding and removing with. I am just stuck on how to actually create this deque. – Aman Kakkar Jan 20 '16 at 02:02
  • I should mention, that they do not require specific implementations in the methods, only a rough outline of what I would do. – Aman Kakkar Jan 20 '16 at 02:04

1 Answers1

0

From comment:

They do not require specific implementations in the methods, only a rough outline of what I would do.

Assuming you want to implement using circular buffer (see Wikipedia), here is a start:

public class Deque implements DequeInterface {
    private Object[] array;
    private int      frontIndex;
    private Object[] rearIndex;
    public Deque() {
        // Allocate array of 100
        // Initialize front index and rear index
    }
    public void addFront(Object o) {
        if (array full) {
            // Increase array size
        }
        array[frontIndex--] = o;
        // Handle frontIndex circling around
    }
    public void addRead(Object o) {
        // TODO
    }
    public Object removeFront() {
        // TODO
    }
    public Object removeRear() {
        // TODO
    }
}

Of course, that outline will be different if you choose to implement using Linked List. Or multiple sub-arrays. Or other implementation.

Andreas
  • 154,647
  • 11
  • 152
  • 247
  • How about implementing using an ArrayDeque of maximum size that can not increase, would I use `ArrayDeque deque = new ArrayDeque(100);` – Aman Kakkar Jan 20 '16 at 02:19