好的,我有这个类库,它使用另一个名为 Book 的类。我想创建一个擦除数组库存中的对象书的方法,但我不知道如何声明该方法的返回值,我想返回对象库以在另一个类中使用它,我将在其中显示所有书在里面。num 变量由用户在另一个类中给出,它表示要擦除的书的编号。数组清单从 0 到 9 开始。
public class Library {
private Book[] inventary;
private int booksquantity;
public Library eraseBook(int num){
for(int i=0 ; i<booksquantity ; i++){
if(i == num-1){
for(int j = i ; j<booksquantity ; j++){
inventary[j] = inventary[j+1];}
}
}return ***;
}
}
//在另一个类中,我会做这样的事情来使用这个方法eraseBook,在一个//switch
case 6:
AppLibrary.cleanscreen();//Static method to erase the screen
System.out.println("What book do u wish to delete?");
String inventary = ghandi.generateInventory();//this makes the //inventory to the user
if(inventary.equals("")){
System.out.println("No books available in the inventary");
}
else{
System.out.println(inventary);
}
int num = Integer.parseInt(s.nextLine());//here i read from the //keyboard the number of book the user wants to delete
//Here the object libary is caled "ghandi"
ghandi.eraseBook(num);//here i use the method
System.out.println("Book erase, please display inventary again");
s.nextLine();
break;
谢谢!!