-2
我正在爲即將到來的測試而學習,並且遇到了一個相當有趣的問題。我試圖在一系列對象中排列一個員工隊列,Books
。我試圖根據員工的優先級從高到低排列他們。Java:排序對象隊列
class Employee{
String name;
int waiting_time;
int retaining_time;
int priority;
Book aBook;
ArrayList <Book> booksRead = new ArrayList<Book>();
public Employee()
{
this.waiting_time=0;
this.retaining_time=0;
}
public int getWaitingTime()
{
return waiting_time;
}
public void setRetainingTime(int retainingtime)
{
retaining_time = retainingtime;
}
public int getRetainingTime()
{
return retaining_time;
}
public void setPriority()
{
priority = waiting_time - retaining_time;
}
public int getPriority()
{
return priority; //sort on
}
}
class Book{
String name;
LocalDate start_date;
LocalDate end_date;
boolean archived;
Queue<Employee> Employees = new LinkedList<>();
public Book()
{
}
//getters and setters omitted
public void setQueue(Queue<Employee> qa)
{
Employees = qa;
}
public Queue<Employee> getQueue()
{
return Employees;
}
}
我的想法是所有元素添加在隊列中,所有的員工,到一個ArrayList,對它們進行排序,然後把他們一個在同一時間回到隊列中,但是,這並不工作,由於到多個錯誤。任何和所有的幫助非常感謝!
我的想法
public static void reorder(ArrayList <Book> booksToCirculate)
{
ArrayList <Book> tmp = new ArrayList <Book>();
for (Book b : booksToCirculate)
{
tmp.add(b);
}
tmp.sort(b.get); // I wanted to sort on the priority here, but i'm not sure how to
}
_due多個errors_你想澄清? –
有什麼錯誤?不知道「一堆書中的員工排隊」是什麼意思。 – duffymo
拍攝我以爲我發佈的代碼,一秒 – Bob