I have two classes. I want to print arrays of objects. These objects have attributes (some of them are String
s), but when the program reads it as (nextLine), it will not print it.
Here is what I mean:
public static void main(String[] args){
String auther,Title,genre;
int ISBN,publicationYear,ISBN2;
if (Book.getBookNo()< archive_size){
System.out.println("ISBN: ");
ISBN=scan.nextInt();
System.out.println("Auther: ");
auther=scan.nextLine(); //here is the problem if I choose next it's ok but no nextLine
scan.nextLine();
System.out.println("Published Year");
publicationYear=scan.nextInt();
System.out.println("Title: ");
Title=scan.nextLine();
scan.nextLine();
System.out.println("Genre: ");
genre=scan.next();
libraryBooks[Book.getBookNo()] = new Book(ISBN,auther,publicationYear,Title,genre);
}
public static void printAll(){
int i=0;
for ( i=0 ; i<Book.getBookNo(); i++)
System.out.println("Book "+(i+1)+"\nISBN: "+libraryBooks[i].getISBN()+
"\nAuthor: "+libraryBooks[i].getAuther()+
"\npublishedyear: "+libraryBooks[i].getPublication()+"\nTitle: "+libraryBooks[i].getTitle()+
"\nGenre: "+libraryBooks[i].getGenre()+"\n");
}