Hello can you help me with adding the borrow-return system to my library, first class is book class with basic attributes, second class is a library with an array of books and third is main with 0 to end the program, 1 adds book, 2 print list of all added books. Whats the best way to add borrow and return system here?
**UPDATED**
public class Kniha { private String Nazov, Autor, Zaner; private int ISBN, pocetStran; boolean pozicana; public Kniha(int ISBN, String Nazov, String Autor, int pocetStran, String Zaner, boolean pozicana){ this.ISBN = ISBN; this.Nazov = Nazov; this.Autor = Autor; this.pocetStran = pocetStran; this.Zaner = Zaner; this.pozicana = pozicana; } public String vratNazov() { return Nazov; } public boolean jePozicana() { return pozicana; } public String toString(){ return "************************" + "\nISBN: " + ISBN + "\nNazov: " + Nazov + "\nAutor: " + Autor + "\nZaner: " + Zaner + "\nPocet Stran: " + pocetStran + "\nJe pozicana: " + pozicana + "\n"; } }
import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class Kniznica{ private List<Kniha> kniznicka; private ArrayList<Historia> historia = new ArrayList<Historia>(); public Kniznica(){ kniznicka = new ArrayList<Kniha>(); } public void pridajKnihu(Kniha kniha){ kniznicka.add(kniha); } public void pridajHistoriu(Historia historicka){ historia.add(historicka); } public void pozicajKnihu(String Nazov){ int found = 0; for (Kniha b : kniznicka) { if (b.vratNazov().equals(Nazov)) { if (found == 0) { found = 1; } if (!b.jePozicana()) { b.pozicana=true; found = 2; break; } } } if (found == 0) { System.out.println("Tato kniha sa u nas nenachadza"); } else if (found == 1) { System.out.println("Tato kniha je uz pozicana"); } else if (found == 2) { System.out.println("Knihu s nazvom " + Nazov + " ste uspesne pozicali"); } } public void vratKnihu(String Nazov){ int found = 0; for (Kniha b : kniznicka) { if (b.vratNazov().equals(Nazov) && b.pozicana==true) { { b.pozicana=false; found = 1; } } } if (found == 0) { System.out.println("Tato kniha k nam nepatri"); } else if (found == 1) { System.out.println("Kniha " + Nazov + " bola vratena"); } } @Override public String toString() { String total = "\n"; Iterator<Kniha> i = kniznicka.iterator(); while(i.hasNext()){ Kniha b = (Kniha) i.next(); total = total + b.toString(); } return total; } public String totoString() { String total = "\n"; Iterator<Historia> i = historia.iterator(); while(i.hasNext()){ Historia b = (Historia) i.next(); total = total + b.toString(); } return total; } }
import java.util.Scanner; public class Aplikacia { static Kniznica ZMK = new Kniznica(); static Scanner in = new Scanner(System.in); static Boolean beh = true; public static void main(String[] args) { System.out.println("**********Víta Vás Žilinská Mestská Knižnica**********"); while (beh) { System.out.println( "\n\nVyberte si z možností?: " + "\nZadaj 0 pre opustenie kniznice" + "\nZadaj 1 na pridanie knihy" + "\nZadaj 2 pre vypisanie zoznamu knih" + "\nZadaj 3 pre požicanie knihy" + "\nZadaj 4 pre vratenie knihy" + "\nZadaj 5 pre historiu pozicanych a vratenych knih\n"); int pom = in.nextInt(); switch (pom) { case 0: System.exit(0); break; case 1: pridajKnihu(); break; case 2: System.out.println(ZMK.toString()); break; case 3: pozicajKnihu(); break; case 4: vratKnihu(); break; case 5: System.out.println(ZMK.totoString()); break; } } System.exit(0); } private static void pridajKnihu() { int ISBN, pocetStran; String Nazov, Autor, Zaner; boolean pozicana = false; System.out.println("\nZadaj ISBN: "); ISBN = in.nextInt(); System.out.println("\nZadaj Nazov: "); Nazov = in.next(); System.out.println("\nZadaj Autora: "); Autor = in.next(); System.out.println("\nEnter Zaner: "); Zaner = in.next(); System.out.println("\nZadaj pocet stran: "); pocetStran = in.nextInt(); Kniha b = new Kniha(ISBN, Nazov, Autor, pocetStran, Zaner, pozicana); ZMK.pridajKnihu(b); System.out.println("\n\n\nKniha bola uložená!"); } private static void pozicajKnihu(){ String Nazov; String akcia = "požičaná"; System.out.println("\nZadaj nazov knihy ktoru si chceš požičat: "); Nazov = in.next(); ZMK.pozicajKnihu(Nazov); Historia b = new Historia(Nazov, akcia); ZMK.pridajHistoriu(b); } private static void vratKnihu(){ String Nazov; String akcia = "vratená"; System.out.println("\nZadaj nazov knihy ktoru chces vratit: "); Nazov = in.next(); ZMK.vratKnihu(Nazov); Historia b = new Historia(Nazov, akcia); ZMK.pridajHistoriu(b); } }