public class Book
{
private String isbn, author, area;
private int length;
public Book(String isbn, String author, String area, int length)
{
this.isbn=isbn;
this.author=author;
this.area=area;
this.length=length;
}
public boolean isLong()
{
if (length>500)
return true;
else
return false;
}
}
public class BookCollection
{
private ArrayList<Book> bookList = new ArrayList<Book>();
public BookCollection()throws IOException
{
Scanner fileScan;
String oneLine;
String isbn, author, area;
int length;
fileScan = new Scanner (new File("books.txt"));
while (fileScan.hasNext())
{
isbn=fileScan.next();
author=fileScan.next();
area=fileScan.next();
length=fileScan.nextInt();
bookList.add(new Book(isbn, author, area, length));
}
}
public class TestBookCollection
{
public static void main (String[] args)throws IOException
{
BookCollection books = new BookCollection();
System.out.println(books);
}
}
여기에 관련 코드가 있습니다. 내 프로젝트는이 책에 대한 정보가있는 텍스트 파일을 읽고 도서 개체의 arraylist에 넣는 것입니다. 내 질문은 : 어떻게 arLylist에있는 개체에 클래스 도서에서 발견 된 isLong() 메서드를 envoking에 갈까요? 메소드의 요점은 객체가> 500 페이지를 가지고 있으면 true를 반환한다는 것입니다. 그렇지 않은 경우는 false를 리턴합니다. 나는 논리에 대해 다소 혼란스럽고 전에 Arraylists와 함께 일한 적은 한 번도 없습니다.Java에서 arraylist의 객체에 대한 메소드 사용
thelist.get (theindex) .isLong() –