Reputation: 369
I've been trying to figure out the reason of this error but I'couldn't :( And I need your help to solve it :)
1.I checked the actual parameter list to make sure it matches the formal parameter list and it did.
2.the constructor Book() with no parameter list worked just fine when I replaced it with the current.
Error:
Library.java:83: cannot find symbol
symbol : constructor Book(int,java.lang.String,java.lang.String,java.lang.String,java.lang.String)
location: class Book
libraryBooks[100-Book.totalNum] = new Book (ISBN,Author,publishedYear,title,genre);
^
1 error
Class Book:
public class Book {
private int ISBN;
private String author;
private String publicationYear;
private String title;
private String genre;
public static int totalNum=1;
private String refCode;
public void Book(int isbn,String auth,String year,String Title,String Genre){
ISBN=isbn;
author=auth;
publicationYear=year;
title=Title;
genre=Genre;
}
public void Book(){
ISBN=1234;
author="-";
publicationYear="2012";
title="-";
genre="-";
}
public static boolean verifyISBN(int isbn1){
int[] n=new int [4];
int isbn=isbn1;
n[3]=isbn%10;
for(int i=2;i>=0;i--){
isbn/=10;
n[i]=isbn%10;}
if (((n[0]*3+n[1]*2+n[2]*1)%4)==n[3])
return true;
return false;
}
}
Class Library:
import java.util.*;
public class Library {
private static Scanner console=new Scanner(System.in);
private static Book [] libraryBooks=new Book [100];
public static void main (String[]args){
System.out.println("Enter the book\'s ISBN");
int ISBN=console.nextInt();
System.out.println("Enter the book\'s author name");
String author=console.next();
System.out.println("Enter the book\'s publish year");
String publicationYear=console.next();
System.out.println("Enter the book\'s title");
String title=console.next();
System.out.println("Enter the book\'s genre");
String genre=console.next();
if(addBook(ISBN,author,publicationYear,title,genre))
System.out.println("The book was successfully added to your library");
else
System.out.println("The book sasn't successfully added to your library");
}
public static boolean addBook(int ISBN,String Author,String publishedYear,String title, String genre){
if (Book.verifyISBN(ISBN)&&(findBook(ISBN)!=-1)){
libraryBooks[100-Book.totalNum] = new Book (ISBN,Author,publishedYear,title,genre);
Book.totalNum++;
return true;}
return false;
}
public static int findBook(int ISBN){
for (int i=99;i>=(100-Book.totalNum);i--)
if(libraryBooks[i].getISBN()==ISBN)
return i;
return -1;
}}
Please help me :( !
Upvotes: 0
Views: 1140
Reputation: 980
Here In this program you makes a very small mistake . You forgot one important property of constructor that is constructor does not have a return type. here you are giving return type as void but internally its automatically returns current class object . I hope now this concept will be more clear for you.
Upvotes: 1
Reputation: 178263
This line isn't a constructor because of the void
keyword (constructors don't have return types). You've created a method that returns void
.
public void Book(int isbn,String auth,String year,String Title,String Genre){
Remove void
:
public Book(int isbn,String auth,String year,String Title,String Genre){
You'll need to do likewise with your other Book
"method":
public Book(){
You didn't define any actual constructors, so Java implicitly included a default constructor that takes no arguments (and does nothing). That is why calling it with no parameters didn't have an error.
Upvotes: 4