first of all, sorry if it's hard understand me not native english speaker point might hard understand.
i trying make basic library booking system, have problem getting user input adjust book details.
what trying book details user input, don't know how properly. tried same style use change status doesn't seem work.
i having difficulties checking , changing books status available booked.
this main program:
public static void main(string[] args) { system.out.println("welcome basic library program! "); system.out.println("insert author, name, genre, isnb, page number "); // 1 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 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:" + " "); } }
you need use scanner in main() class. example in code:
scanner input = new scanner (system.in);
needs entered before try user's input. allow call input.nextint();
successfully.
see previous question here: how can user input in java?
Comments
Post a Comment