Results 1 to 3 of 3
- 12-03-2012, 03:32 PM #1
Member
- Join Date
- Dec 2012
- Posts
- 3
- Rep Power
- 0
Create a function that sorts an arraylist of objects
Hey , i need help with creating a function that sorts objects in an ascending order in the class ClientQueue.I've tried to do a lot of times but all i get is erros...The function is called addClient and,everytime it's called, it has to add a Client object in the correct order in the arraylist.The class Client contains a variable called priority and the arraylist is sorted according to the priority of the clients.The related codes are the following;
Java Code:public class Cashier { private boolean open; private Client queue; Client currentClient; int serviceTime; int idleTime; public Cashier(boolean open) { this.open=open; }Java Code:import java.util.Random; public class Client { public int priority; private int numItems; private double paysCash; public Client(int i) { int creationTime=i; int MAX_TIME=43200; Random rnd=new Random(); numItems=rnd.nextInt(49)+1; //plh8os eidwn final int P_PAYS_CASH=rnd.nextInt(10); int P_IS_SPECIAL=rnd.nextInt(10); if(P_IS_SPECIAL>1) { priority=creationTime; } else { priority=creationTime-MAX_TIME; } }
- 12-03-2012, 04:03 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: Create a function that sorts an arraylist of objects
You have no ClientQueue class.
There is no array.
Or even an attempt at the addClient() method.Please do not ask for code as refusal often offends.
- 12-03-2012, 06:33 PM #3
Senior Member
- Join Date
- Nov 2012
- Posts
- 223
- Rep Power
- 1
Similar Threads
-
Noob question - Create objects using objects as parameters
By pantaloc in forum New To JavaReplies: 12Last Post: 04-29-2012, 02:55 PM -
recursive function to create many objects?
By dacoolest in forum New To JavaReplies: 1Last Post: 11-22-2011, 08:03 PM -
Trying to create an undo function using an arraylist.
By Spirit356 in forum New To JavaReplies: 6Last Post: 04-27-2010, 07:01 PM -
Search function for ArrayList?
By javanoobie in forum New To JavaReplies: 11Last Post: 04-17-2009, 08:38 PM -
read txt file,with some records, create objects and store objects in tables of a db.
By stamv in forum JDBCReplies: 1Last Post: 01-22-2009, 04:25 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks