📄 userinfo.java
字号:
import javax.swing.JOptionPane;
/*
* Created on 2005-5-18
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
/**
* @author ade
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class UserInfo {
private int userID;
private String userName;
private long[] borrowTime = {0,0,0,0,0};
private int[] borrowedBkID = {0,0,0,0,0};
public int getUserID(){
return userID;
}
public String getUserName(){
return userName;
}
public void setUserID( int id ){
userID = id;
}
public boolean setUserName( String name ){
char c;
for(int i = 0 ; i <= name.length()-1 ; i++){
c = name.charAt(i);
if( !( (c >= 65 && c <= 90) || (c >= 97 && c<=122) ) ){
JOptionPane.showMessageDialog( null,"illegal character:'" + c + "' in a user name" );
return false;
}
}
userName = name;
return true;
}
public boolean borrowBook( int bkID ,long time){
if( getAvailable() != 0 ) {
for( int j = 0; j <= borrowedBkID.length-1; j++ ){
if(borrowedBkID[j] == bkID){
JOptionPane.showMessageDialog(null,"您已经借阅了这本书!");
return false;
}
}
for( int i = 0; i <= borrowedBkID.length-1; i++ ){
if( borrowedBkID[i] == 0 ){
borrowedBkID[i] = bkID;
borrowTime[i] = time;
return true;
}
}
}
return false;
}
public long getBorrowTime( int bookID ){
for( int i = 0 ; i <= borrowedBkID.length - 1 ; i++ ){
if( borrowedBkID[i] == bookID )
return borrowTime[i];
}
return 0;
}
public boolean returnBook( int bkID ){
int i;
for( i = 0; i <= borrowedBkID.length - 1; i++ ){
if( borrowedBkID[i] == bkID ){
borrowedBkID[i] = 0;
return true;
}
}
return false;
}
/**
* @return
*/
public int[] getBorrowedBook() {
// TODO Auto-generated method stub
return borrowedBkID;
}
public int getAvailable(){
int i,sum=0;
for( i = 0; i <= borrowedBkID.length-1; i++ ){
if( borrowedBkID[i] == 0 ) sum++;
}
return sum;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -