i am pretty new to object-orientated Java. I am trying to add books into a "bookshelf", in order to print out the author, title and year of release of the book. The problem I am encountering is that the console prints out the values for the same book and not for both of the added ones.
public class Bookshelf {
public static void main(String[] args) {
registerBooks();
}
public static void registerBooks() {
Book b1 = new Book("Ikigai", "Ken Mogi", 2018);
Book b2 = new Book("The Alchemist", "Paulo Coelho", 1988);
System.out.println(getName(b1));
System.out.println(getName(b2));
}
static String getName(Book b) {
return Book.name;
}
static String getAuthor(Book b) {
return Book.author;
}
static int getYear(Book b) {
return Book.year;
}
}
public class Book {
static String name;
static String author;
static int year;
public Book(String bn, String ba, int be) {
name = bn;
author = ba;
year = be;
}
}