this is my application class where i have instead array of objects
loanBook
is a super class andloanDocumentry
is a sub class that extends loanBook. This is declared at the top of the application classpublic static loanBook[] bookArray = new loanDocumetry[5];
then in my application class i have to add new documentry book so i use the scanner for inputs and then use them to add the new object
bookArray[i] = new loanDocumentry(
title, author, publisher, year, noOfPages, genre);
and the book count in loanBook
increases so I know each time I run the method it creates new book but when then printing the array out it looks like it never added any of those books to the array and that the only one i have added is the last one
Application Class:
public class ApplicationClass {
public static Scanner input = new Scanner(System.in);
public static loanBook[] bookArray = new loanDocumentry[5];
public static void main(String[] args) {
addBook();
}
public static void addBook() {
input.nextLine();
String title;
String author;
String publisher;
int year;
int noOfPages;
String genre;
String choice;
int i = 0;
System.out.print("\nTITLE of the book: ");
title = input.nextLine();
System.out.print("AUTHOR of the book: ");
author = input.nextLine();
System.out.print("PUBLISHER of the book: ");
publisher = input.nextLine();
System.out.print("YEAR book was published in: ");
year = input.nextInt();
System.out.print("NUMBER OF PAGES the book has: ");
noOfPages = input.nextInt();
System.out.print("GENRE of the book: ");
input.nextLine();
genre = input.nextLine();
bookArray[i] = new loanDocuemntry(title, author, publisher, year, noOfPages, genre);
i++;
}
loanBook Superclass & loanDocumentry Sub class both use set and gets