Answer:
public class Book {
private String title;
private String author;
private int yearPublished;
private long ISBN;
//The Constructor for all the feilds
public Book(String title, String author, int yearPublished, long ISBN) {
this.title = title;
this.author = author;
this.yearPublished = yearPublished;
this.ISBN = ISBN;
}
//Mutator methods (set) to Set values of all the fields
public void setTitle(String title) {
this.title = title;
}
public void setAuthor(String author) {
this.author = author;
}
public void setYearPublished(int yearPublished) {
this.yearPublished = yearPublished;
}
public void setISBN(long ISBN) {
this.ISBN = ISBN;
}
//Accessor Methods (getters) for all the feilds
public String getTitle() {
return title;
}
public String getAuthor() {
return author;
}
public int getYearPublished() {
return yearPublished;
}
public long getISBN() {
return ISBN;
}
}
// The Demo Class creating three instances of this class
class BookDemo{
public static void main(String[] args) {
Book bookOne = new Book("The Lion and the Princess","David A.",2000,12334556);
Book bookTwo = new Book ("Me and You", "Jane G.", 2001, 4567342);
Book bookThree = new Book("together forever", "Baneely H.",2019,34666);
}
}
Step-by-step explanation:
- Please pay attention to the comments provided in the solution
- Using Java Programming Language
- The class Book is created with the required fields
- The constructor is created to initialize the values of the fields
- Getter methods are created
- Setter Methods are Created
- A demo Class BookDemo that creates three objects of the Book class is the created (This can be in the same file as the Book class but cannot start with the keyword public or in a separate file with the keyword public class BookDemo)
- Inside BookDemo class, three instances of the Book class are created and initialized.