gak
12-30-2006, 03:29 PM
Hi,
I'm new to java and would really appreciate some advice on the following:
I've made 3 java objects that work together - a Worker object, a Job object and a Rosta object.
All the workers are referenced in an ArrayList in the Rosta object.
All the jobs are also referenced in an ArrayList in the Rosta object.
Jobs are allocated to Workers, who then store a reference of to their allocated jobs in their own ArrayList.
My allocateJob() method looks like this:
public void allocateJob(Job j) {
willDo.add(j); //-------willDo is the name of the workers' ArrayList of jobs
}
All of the above is working ok, but I want to set individual maximum ammounts to be allocated for each worker.
I then added a maxJobs attribute to each Worker with appropriate get/set accessor methods and an isBusy() method which looks like this:
public boolean isBusy() {
if(willDo.size() == this.getMaxJobs()) return true;
else return false;
}
This parts compile and work ok, but I now want to change my allocateJob() method to use the isBusy() method, so that a Job will only be allocated to a Worker who isn't busy!
I tried this, but it doesn't work when I run it:
public void allocateJob(Job j) {
if(this.isBusy() == true) {
willDo.add(j);
} else if (this.isBusy() == false) {
System.out.println("Helper is currently busy");
}
}
If anyone could give me any help or advice on what I've done wrong, I'd be very grateful!
Many thanks,
Gak
I'm new to java and would really appreciate some advice on the following:
I've made 3 java objects that work together - a Worker object, a Job object and a Rosta object.
All the workers are referenced in an ArrayList in the Rosta object.
All the jobs are also referenced in an ArrayList in the Rosta object.
Jobs are allocated to Workers, who then store a reference of to their allocated jobs in their own ArrayList.
My allocateJob() method looks like this:
public void allocateJob(Job j) {
willDo.add(j); //-------willDo is the name of the workers' ArrayList of jobs
}
All of the above is working ok, but I want to set individual maximum ammounts to be allocated for each worker.
I then added a maxJobs attribute to each Worker with appropriate get/set accessor methods and an isBusy() method which looks like this:
public boolean isBusy() {
if(willDo.size() == this.getMaxJobs()) return true;
else return false;
}
This parts compile and work ok, but I now want to change my allocateJob() method to use the isBusy() method, so that a Job will only be allocated to a Worker who isn't busy!
I tried this, but it doesn't work when I run it:
public void allocateJob(Job j) {
if(this.isBusy() == true) {
willDo.add(j);
} else if (this.isBusy() == false) {
System.out.println("Helper is currently busy");
}
}
If anyone could give me any help or advice on what I've done wrong, I'd be very grateful!
Many thanks,
Gak