Getting a error: array required, but String found. I checked and rechecked, yet couldn't find anything wrong with my code. What's going wrong? I have been introduced to java a year ago, but only when i started working on a project to develop a library management system do I realise the serious deficiencies in my knowledge.
import java.util.Scanner;
public class library{
book[] bk = new book[5];
public static void main(String[] args){
Scanner input = new Scanner(System.in);
library mainObj = new library();
mainObj.addBooks();
}
public void addBooks(){
Scanner input = new Scanner(System.in);
System.out.print("Book Name: ");
String bk = input.nextLine();
System.out.print("Author Name: ");
String aun = input.nextLine();
System.out.print("Id: ");
String i = input.nextLine();
bk[book.getTotalBookCount()] = new book(bk, aun, i);
}
}
class book{
String name;
String authorName;
String id;
static int totalBookCount = 0;
book(String bkn, String aun, String i){
name = bkn;
authorName = aun;
id = i;
totalBookCount++;
System.out.println("Book Added!! ");
}
}
String bk="book name";). Note that using good long names let you avoid such problem.