• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with BlueJ and Arrays!  RSS feed

 
Jack Brown
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have created an application for a car recovery company, I add jobs which have fields such as job ref, customer name, and what time the job was logged on the system, and what time the job was completed, the time the job was completed stays null until it has been logged as complete.

I need a way to display all the jobs which haven't been attended how can I do this?

Thanks,

Jack.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe have multiple lists:

jobsInQueue which holds all the jobs which have not been handled yet

jobsInProgress which are all the jobs which have been started but not completed

jobsCompleted which are all the jobs which have been completed.

When you get a new job, you create the Object and put it in the first list. Then when someone starts working on it, you pull it from the jobsInQueue list and put it into the jobsInProgess list. Finally, once a job is complete you pull it from the jobsInProgress list and put it into the jobsCompleted one. Then you know how to get the jobs you want without having to search - just reference the correct list.

Alternatively, you determine which field in the Job object determines "hasn't been attended" and search your list for the first one which has that field in the proper state. For example, if "hasn't been attended" means the job hasn't been completed, then you search the list for the first job which has the "time the job was completed" field set to null.

Something that may help you is if you sort the list first, perhaps sort on the 'time the job was completed' field first, making a null value the first in value in order. Then do a second order sort on the 'time the job was logged on' so that the first value on your list would be the first job to come in that is not completed. Look at Array's sort(T[], Comparator<? super T>) method if you are using arrays, or a TreeSet if you are using collections.
 
Jack Brown
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is how I want to do it but cant figure out the code for the whole creating and adding to the list.

I need a list which contains all the reference numbers of every job which hasn't been attended yet.

Once its been attended I need code to remove it from the list.

I also need to display the list of the reference numbers for the jobs which haven't been attended.

Seems pretty simple but I'm new to Java and can't figure out the code.

Thanks,

Jack.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I think you are trying do too much all at once. Get yourself a Task class (or similar) with fields like price, description and whetherDone. Test that by calling its methods. Enhance that by not allowing the same Task to be done twice.
Once you have got that working properly, then consider two tasks.
I don’t like BlueJ myself, but it does allow you to click the carryOut method and see the changes in the state of the object.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!