First of all, I am sorry if it's hard to understand me as I am not native English speaker my point might be hard to understand.
I am trying to make a very basic library booking system, but I have a problem with getting user input to adjust book details.
What I am trying to do is to get the book details from user input, but I don't know how to do this properly. I tried the same style that I use to change status but it doesn't seem to work.
I am also having some difficulties with checking and changing the books status from available to booked.
This is the main program:
public static void main(String[] args) {
System.out.println("Welcome to the basic library program! ");
System.out.println("Insert author, name, genre, ISNB, page number ");
// this one is wrong.
Book booking = new Book("Mary","Random Book","Horror",69,69);
System.out.println("Print book information? 1 = yes 2 = no?");
int answer = input.nextInt();
if (answer == 1) {
booking.printBook();
}
else {
}
System.out.println("Check books status? 1= yes 2= no");
int status = input.nextInt();
if (status == 1) {
booking.checkStatus();
}
else {
}
System.out.println("Change books status: 1 = Avaible 2 = Booked 3 = Lost ");
int availability = input.nextInt();
booking.changeAvailability(availability);
}
And this is the book class:
public class Book {
private String author;
private String name;
private String genre;
private int isbn;
private int pageNumber;
private int availability;
private String setAvailability;
public Book(String authorInput, String nameInput, String genreInput, int isbnInput, int pageInput) {
this.author = authorInput;
this.name = nameInput;
this.genre = genreInput;
this.isbn = isbnInput;
this.pageNumber = pageInput;
}
public void changeAvailability(int availability) {
if (availability == 1) {
setAvailability = "Avaible";
System.out.println("Avaible.");
}
else if (availability == 2) {
setAvailability = "Not avaible";
System.out.println("Not avaible.");
}
else if (availability == 3) {
setAvailability = "Lost";
System.out.println("Book missing.");
}
else {
System.out.println("Unknown input: Program closing..");
System.exit(1);
}
}
public String checkStatus() {
return this.setAvailability;
}
public void printBook() {
System.out.print("Author: " + this.author + "\nName: " + this.name + "\nGenre: " + this.genre + "\nISBN: " + this.isbn + "\nPages: " + this.pageNumber + "\nAvailability:" + " ");
}
}