-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;
}
}
我只想知道如何设置一个枚举。如果你能教育我,将不胜感激。 –
好的,我会试试。删除评论。 (对不起) –