gpt4 book ai didi

java - 尝试从 arraylist 打印方法

转载 作者:行者123 更新时间:2023-12-02 05:03:59 25 4
gpt4 key购买 nike

我正在尝试使用库类中的数组打印成员类的标题
公共(public)课书给了我这个错误: http://screencast.com/t/tqpJp2BF8sH

       {
// instance variables - replace the example below with your own
private int x;
private Integer bookid;
private String author;
private String title;
private String ficornonfic;

/**
* Constructor for objects of class Book
*/
public Book(Integer bookID, String Author, String Title, String FictionORnonfiction )
{
bookid = bookID;
author = Author;
title = Title ;
ficornonfic = FictionORnonfiction;
x = 0;
}


public String PrintListOfBooks()
{

return title;

}

public String toString() {
return "Title:" + title + " BookId: " + bookid + " Author: " + author + ".";
}
public int getTitle() {
return this.title;
}
}
---------------------------------------------------------

这是我的图书馆类(class)

   import java.util.ArrayList;



public class Library
{


private ArrayList<Member>listOfMembers;
public Library()
{
listOfMembers = new ArrayList<Member>();
listOfBooks = new ArrayList<Book>();
}
public void storeMember(Member Member)
{
listOfMembers.add(Member);
}
public int numberOfMembers()
{
return listOfMembers.size();
}

public void listMembers()
{
for (int item=0; item<listOfMembers.size(); item++ ) {
Member m = listOfMembers.get (item);
System.out.println(m.GetWholeName());
}
}

public Member findMember(int id) {

for(Member member : listOfMembers) {
if (member.getId() == id) {
return member;
}
}

return null;
}

private ArrayList<Book>listOfBooks;

public void storeBook(Book Book)
{
listOfBooks.add(Book);
}
public int numberOfBooks()
{
return listOfBooks.size();
}

public void listBooks()
{
for (int item=0; item<listOfBooks.size(); item++ ) {
Book b = listOfBooks.get (item);
System.out.println(b.PrintListOfBooks());
}
}

public Book findBook(string title) {

for(Book book : listOfBooks) {
if (book.getId() == id) {
return book;
}
}

return null;
}


}

我正在尝试使用库类中的数组打印成员类的标题
公共(public)课书给了我这个错误: http://screencast.com/t/tqpJp2BF8sH

最佳答案

title 是一个 String,而不是 int。您可以更改方法签名以匹配字段类型:

public String getTitle() {
return this.title;
}

关于java - 尝试从 arraylist 打印方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27975135/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com