将以下代码重新用java写,功能和逻辑不变,语句需要变化public boolean outBook(String bookId , int num) { Book b = getById(bookId); if(b == null ) return false; if(b.getIsbn().equals(bookId)) { b.setStore(b.getStore()-num); return true; } return false; } /* * printf("%5d",a) */ public int buyBook(String bookId,int num) { Book b = getById(bookId); if(b == null) return -1; if(b.getStore() >= num) return 1; return 0; } public List<String> getEXNames(int option){ return ExFactory.getAllEX(); } public EX buyEx(int exCode) { return ExFactory.create(exCode); }
时间: 2023-06-25 07:04:39 浏览: 66
Java if(boolean)和if(boolean=true)区别解析
public boolean outBook(String bookId, int num) {
Book b = getById(bookId);
if (b == null) {
return false;
}
if (b.getIsbn().equals(bookId)) {
b.setStore(b.getStore() - num);
return true;
}
return false;
}
public int buyBook(String bookId, int num) {
Book b = getById(bookId);
if (b == null) {
return -1;
}
if (b.getStore() >= num) {
return 1;
}
return 0;
}
public List<String> getEXNames(int option) {
return ExFactory.getAllEX();
}
public EX buyEx(int exCode) {
return ExFactory.create(exCode);
}
阅读全文