I have a Java application with 4 Java classes which are Menu,LoanBook(superclass), FictionBook(extends loanBook), NonFictionBook (extends loanBook)
I'm stuck on a method - the purpose of the method is to issue a book from my array to a pupil. I aim to search for a book and add pupil details to that book. I cant work out where im going wrong, i just cant get my head around this method.
Please ignore any extra variables, but take into account everything else, any advice would be very helpful, if any more information is required..
My question is for somebody to look over this, tell me what's not needed and where i am going wrong. Is there an easier way to do this?
PS i have changed the below code from original, but with this i am getting a runtime error after i have added the name
static void issueBook() {
int choice,x = 0;
String title,name,date;
boolean found = false;
System.out.println("1.Fiction or 2.NonFiction?");
choice = keyboard.nextInt();
if (choice == 1){
System.out.println("Please enter the title of the book to loan:");
title = keyboard.next();
System.out.println("Please enter your name:");
name = keyboard.next();
date = "todays date";
do {
if (fictionBooksArray[x].getTitle().equals(title)){
found = true;
fictionBooksArray[x].setOnLoan(true);
fictionBooksArray[location].setName(name);
fictionBooksArray[location].setDate(date);
System.out.println("Loan successful ");
}
else x++;
}
while ((x < fictionBooksArray.length)&& (!found));
if (!found){
System.out.println("This book title could not be located.");
}
}
This seems like homework, so I won't post how to do this, but some general method structure might be like so:
Edit, full example as requested:
Implied code:
Example code: