Solved

Passing objects to linked list!

Posted on 2004-04-11
6
203 Views
Last Modified: 2010-03-31
Greetings everyone!

Background:

I got this uni project for printerjobs where i'm using singly linked list. the approch i'm taking is instead of declaring the varibles(Printer name, printer source, doc name etc..) in the node class i created another class called printer jobs and i only created a varible of object type. in printer jobs i have all the setters and getterin there instead of the node class.

when adding i add the printerjob object which have values of (Printer name, printer source, doc name etc..) to data object in node class and so on....

PrinterJob myPrinterJob = new PrinterJob("New Printer Job");
myPrinterJob.setJobNo(1);
myPrinterJob.setJobPrio(1);
myPrinterJob.setJobSource("CPA1");
myPrinterJob.setDocName("EasyProgramming.doc");
myPrinterJob.setDocSize("3 MB");
Passing object to link list but....


myPrinterQueue.addToTail(myPrinterJob);

PrinterJob myPrinterJob2= new PrinterJob("New Printer Job");
myPrinterJob.setJobNo(1);

and so on................

Problem:

Now i'm implenting my program in dos prombt, so i want to add unlimited number of data with having to create new printerjob object everytime when i'm adding i want it to create itself everytime heres the link of my app

http://www.qandala.com/1.zip


looking forward for help

Abdi
0
Comment
Question by:qandala
  • 2
6 Comments
 
LVL 5

Expert Comment

by:lwinkenb
ID: 10801703
What do you mean by wanting it to create itself?
0
 

Author Comment

by:qandala
ID: 10802120
I mean instead of creating fixed number of objects data type inside the file i want to be able to store/pass objects in the node!

Object myObject= new Object();
List.addToTail(myObject)

but what i want is a way where i can make/create objects new object everytime when adding!

i hope you understode what i meant

Regards
0
 

Author Comment

by:qandala
ID: 10805599
I mean instead of creating fixed number of objects data type inside the file i want to be able to store/pass objects in the node!

Object myObject= new Object();
List.addToTail(myObject)

but what i want is a way where i can make/create objects new object everytime when adding!

i hope you understode what i meant

Regards
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 130 total points
ID: 10806041
>>but what i want is a way where i can make/create objects new object everytime when adding

If you wanted an 'auto-initialise' facility how would it know which values to initialize to? All you could do is provide default values and get the job number from the list size:

//overridden (no arg)

public Node addToTail() {

     PrinterJob myPrinterJob = new PrinterJob("New Printer Job");
     myPrinterJob.setJobNo(getSize());
     //etc
     Node node = new Node(myPrinterJob);
     // set pointers etc.
     return node;

}
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
IT Company 5 69
word0 challenge 3 58
java  and programming certification ? 4 65
micro services vs rest web services 16 53
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now