저는 기초 클래스 작성 자습서를 작성하고 아래 지침이 제공되는 초보자입니다. 지시에 따라 형식의 메서드가 인수에 적용되지 않습니다.
1) Create a new class called Book.
2) Create fields for title, author, numPages, and isbn.
3) Create a method called toString that appropriately describes the book.
4) In the file, BookRunner.java:
a) Declare two book variables
b) Instantiate two book objects and set their fields.
c) Print descriptions of the book objects using their toString methods.
그래서 나는 두 개의 클래스를 사용하여 작업 있었고, 내가 방법
toString
를 호출 마지막 두 줄 때까지 내 코드가 오류를 보여줍니다
public class Book {
public String title;
public String author;
public String numPages;
public String isbn;
public void toString(String bookName) {
String description = "Title:" + title + "Author"+ author + "Num. of pages" + numPages + "ISBN" + isbn;
System.out.println(description);
}
public class Ex1_BookRunner {
public static void main(String[] args) {
Book firstBook;
Book secondBook;
firstBook = new Book();
secondBook = new Book();
firstBook.title = "One Piece";
firstBook.author = "Oda-Sensei";
firstBook.numPages = "100";
firstBook.isbn = "123456";
secondBook.title = "Life of Megan Fox";
secondBook.author = "Micheal Bay";
secondBook.numPages = "200";
secondBook.isbn = "098765";
toString(firstBook);
toString(secondBook);
}
}
아래의 코드를 볼 수 있습니다.
나는
The method toString() in the type Object is not applicable for the arguments (Book)
아래의 오류가 내 메소드 선언 어딘가에서 몇 가지 근본적인 오류를 만드는 건가요거야? 나는 다른 질문을 똑같은 질문으로 보았지만, 아직 배운 적이없는 코드 구문을 다루기 때문에 설명을 이해하는 데 어려움이 있습니다.
어떤 도움에 감사드립니다 :)
는 같은 날 것으로 보인다이'numPages'없이,'int'로 더 적합 할 것입니다 시도가 있습니까? – Floegipoky