-3
我很新來面向對象編程,並且正在嘗試創建一個庫系統模擬。我試圖建立一套方法,其中:如何創建一個枚舉方法(java)
- 設置庫書的地位REFERENCE_ONLY(ENUM)
- 將圖書館的書作爲AVAILABLE_FOR_LENDING(ENUM)
- 一個布爾值,它決定的狀態如果這本書是ON_LOAN(ENUM)
我的代碼:
public class LibrarySimulation {
public static void main(String[] args) {
}
public static String getBookAuthor(){
return null;
}
}
class LibraryBook {
public enum status {REFERENCE_ONLY, ON_LOAN, AVAILABLE_FOR_LENDING};
String bookAuthor;
String bookTitle;
int bookPages;
String classification;
int timesBorrowed;
int reservations;
static int totalOnLoan;
/**
* Constructor with arguments for a LibraryBook’s author(s),
* title and number of pages
* @param bookAuthor the names of the author(s) of this
* LibraryBook
* @param bookTitle the title of this LibraryBook
* @param bookPages the number of pages of this
* LibraryBook
*/
public LibraryBook(String bookAuthor,String bookTitle, int bookPages){
bookAuthor = null;
bookTitle = null;
bookPages = 0;
}
/**
* A method to reset the Library classification of this
* LibraryBook
* @param bookClass the proposed new classification
* @return true, if the proposed new
* classification has at
* least 3 characters to which
* the Library classification is
* reset.
* false, otherwise.
*/
public boolean setClassification(String bookClass){
if(bookClass.length() >= 3){
return false;
}
else{
return true;
}
}
public String setAsReferenceOnly(){
LibraryBook book = new LibraryBook(status.REFERENCE_ONLY);
}
//method for getting bookAuthor
public String getBookAuthor(){
return bookAuthor;
}
//method for getting bookTitle
public String getBookTitle(){
return bookTitle;
}
//method for getting bookPages
public int getBookPages(){
return bookPages;
}
//method for getting classification
public String getClassification(){
return classification;
}
//method for getting TimesBorrowed
public int getTimesBorrowed(){
return timesBorrowed;
}
}
我只想知道如何設置一個枚舉。如果你能教育我,將不勝感激。 –
好的,我會試試。刪除評論。 (對不起) –