Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2003

Tip: Looking for answers? Try searching our database.

Confusing for me, Easy for you :P

Thread view: 
Jazz - 31 Oct 2003 07:11 GMT
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
Anton Spaans - 31 Oct 2003 15:52 GMT
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.

> 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
[quoted text clipped - 27 lines]
>
> Jazz


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.