File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes programming to the interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic

programming to the interface

Dianne Gerrelli
Ranch Hand

Joined: Dec 21, 2005
Posts: 45
I need some advice with an exercise that I am doing which I have got stuck with and can not get past what ever I try so was hoping that someone may be able to help. My tutor says I am very close but it does not feel like it!

I need to implement a method called reset()

this method should return a new empty TrafficQueue (which is designed as an ArrayList) the same size as the current one.

I must stick to the method signatures specified in the interface, so must use

public ThingBeingSimulated reset() {

The class ThingBeingSimulated is a programme that I have been give to allow the TrafficQueue to be shown on the screen. TrafficQueue is the class and queue should be the instance of the class. I have tried all of the following which give a range of compilation errors.

public ThingBeingSimulated reset(){
return this.queue(size);

public ThingBeingSimulated reset(){
return new TrafficQueue(size);}

public ThingBeingSimulated reset(){
return new TrafficQueue(queue.size);}

public ThingBeingSimulated reset(){
return new queue(queue.size):}

public ThingBeingSimulated reset(){
queue = new ArrayList<RoadVehicle>(size);
return queue(size);

public ThingBeingSimulated reset(){
return new ThingBeingSimulated(queue.size);}

I would be grateful for any help what so ever.

fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11957

There's no need to make the same post in multiple forums - in fact, it's generally discouraged. You can read why here.

I think we're gonna close this one, as there are responses coming in this one.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
I agree. Here's the link:
subject: programming to the interface
It's not a secret anymore!