Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to declare method return value?
    primarykey
    data
    text
    <p>Ok, i have this class Libray that uses another class named Book. I want to make a method that erase an object book in the array inventary, but i dont how to declare the return value of the method, i want to return the object libray to use it in another class, where i will display all the books in it. The num variable its given by the user in another class, its represents the number of the book to erase. The array inventary starts from 0 to 9.</p> <pre><code>public class Library { private Book[] inventary; private int booksquantity; public Library eraseBook(int num){ for(int i=0 ; i&lt;booksquantity ; i++){ if(i == num-1){ for(int j = i ; j&lt;booksquantity ; j++){ inventary[j] = inventary[j+1];} } }return ***; } } </code></pre> <p>//In the other class i would make something like this to use this method eraseBook, in a //switch</p> <pre><code>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; </code></pre> <p>Thanks!!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload