Confusing for me, Easy for you :P

J

Jazz

Alright I'm new to Java and I'm in the middle of doing my java project. I
have a super class called SFactory that has 2 protected Queues named q1 and
q2. I was asked to create a class called PlateFactory that will extend
SPlateFactory.

The Factory constructor:

public Factory(int n)
/* builds two identical queues containing n randomly-
generated plates. The variables q1 and q2 (inherited
from SPlateFactory) may be initialized and accessed
directly in this constructor. */

This is what I did:

public Factory(int n) {
for (int i = 0; i < n;i++){
Plate p = new Plate();
q1.enqueue(p);
q2.enqueue(p.getCopy());
}
}

This is fine except that I need to first actually create the
2 new queues (empty) that q1 and q2 will reference.

How do i do that?

Thanks

Jazz
 
A

Anton Spaans

What about these extra two lines (providing that your superclass SFactory
has not yet created these two queues....)?:

public Factory(int n) {
q1 = new Queue();
q2 = new Queue();
for (int i = 0; i < n;i++){
Plate p = new Plate();
q1.enqueue(p);
q2.enqueue(p.getCopy());
}
}
-- Anton.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top