?? book.java
字號:
import java.util.*;
public class Book extends StringAdapter{
static int Id=0;
private String title;
private int id=Id++;
private int borrower=-1;//borrower id
private boolean available=true;
public Book(String title){
this.title=title;
}
/*return whether borrow is sucessful*/
public synchronized boolean borrow(int borrower){
if(available==false)
return false;
else{
this.borrower=borrower;
available=false;
return true;
}
}
/*return whether retun is sucessful*/
public synchronized boolean retun(int borrower){
if(borrower!=this.borrower)
return false;
else{
this.borrower=-1;
available=true;
return true;
}
}
public synchronized boolean isAvaliable(){
return available;
}
public synchronized String toString(){
return (adapt(id,25)+adapt(title,25)+adapt(borrower,25));
}
public String getTitle(){
return title;
}
public String getId(){
return Integer.toString(id);
}
public synchronized int getBorrower(){
return borrower;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -