package com.mycompany.mohamad_hamza_rawyh; import java.time.LocalDate; import java.util.ArrayList; import java.util.List; import java.util.Scanner; abstract class Item { private int id; private String address, specialization, year_of_publiction; public Item(int id, String address, String year_of_publiction, String specialization) { this.id = id; this.address = address; this.year_of_publiction = year_of_publiction; this.specialization = specialization; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public String getYear_of_publiction() { return year_of_publiction; } public void setYear_of_publiction(String year_of_publiction) { this.year_of_publiction = year_of_publiction; } public String getSpecialization() { return specialization; } public void setSpecialization(String specialization) { this.specialization = specialization; } public abstract void printtype(); public void printInfo() { System.out.println("id=" + id + ", address=" + address + ", year_of_publiction=" + year_of_publiction + ", specialization=" + specialization + '}'); } } class Book extends Item { private String name_of_author;//مولف private int number_of_page;//عدد صفحات الكتاب private String publish_hous;//دار النشر public Book(String name_of_author, int number_of_page, String publish_hous, int id, String address, String year_of_publiction, String specialization) { super(id, address, year_of_publiction, specialization); this.name_of_author = name_of_author; this.number_of_page = number_of_page; this.publish_hous = publish_hous; } public String getName_of_author() { return name_of_author; } public void setName_of_author(String name_of_author) { this.name_of_author = name_of_author; } public int getNumber_of_page() { return number_of_page; } public void setNumber_of_page(int number_of_page) { this.number_of_page = number_of_page; } public String getPublish_hous() { return publish_hous; } public void setPublish_hous(String publish_hous) { this.publish_hous = publish_hous; } public void printInfo() { System.out.print("Book{" + "name_of_author=" + name_of_author + ", number_of_page=" + number_of_page + ", publish_hous=" + publish_hous); super.printInfo(); } @Override public void printtype() { System.out.println("Book"); } } class Project extends Item { private String work_team, year; public Project(String work_team, String year, int id, String address, String year_of_publiction, String specialization) { super(id, address, year_of_publiction, specialization); this.work_team = work_team; this.year = year; } public String getWork_team() { return work_team; } public void setWork_team(String work_team) { this.work_team = work_team; } public String getYear() { return year; } public void setYear(String year) { this.year = year; } @Override public void printtype() { System.out.println("project"); } public void printInfo() { System.out.print("Project{" + "work_team=" + work_team + ", year=" + year); super.printInfo(); } } class Library { List itemsn = new ArrayList<>(); List members = new ArrayList<>(); List borrowd = new ArrayList<>(); public void addItem(Item item) { itemsn.add(item); System.out.println("Item added"); }//اضافة عنصر public void addmember(Member member) { members.add(member); System.out.println("Member added"); }//اضافة عضو public void view_All_Book() { boolean found = false; for (Item item : itemsn) { if (item instanceof Book) { Book b = (Book) item; b.printInfo(); found = true; } } if (!found) { System.out.println("there are no books in library"); } }// عرض جميع الكتب public List displayThirdYearProject() { List projects = new ArrayList<>(); boolean found = false; for (Item item : itemsn) { if (item instanceof Project) { Project project = (Project) item; if (project.getYear().equals("THIRD")) { projects.add(project); found = true; } } } if (!found) { System.out.println("There are no Third-year projects"); } return projects; }//تابع يعرض مشاريع السنة الثالثة public void displayMemberWhoBorrowartifecal() { boolean found = false; for (Member member : members) { for (Item item : member.getborrowditem()) { if (item instanceof Book) { Book b = (Book) item; if (b.getSpecialization().equals("artifecal")) { System.out.println("name:" + member.getName()); } } } found = true; } if (!found) { System.out.println("there are no borrowed members artifecal "); } }//عرض جميع كتب الذكاء الاصتناعي public List getCurrentlyBorrowebook() { List borrowed = new ArrayList<>(); boolean found = false; for (Member member : members) { for (Item i : member.getborrowditem()) { if (i instanceof Book) { borrowed.add((Book) i); } } found = true; } if (!found) { System.out.println("There are no books on loan"); } return borrowed; }// عرض الكتب المعارة حالياً public Member findMember(String memberName) { for (Member member : members) { if (member.getName().equals(memberName)) { return member; } } return null; }//البحث عن عضو public Item findItem(int id) { for (Item item : itemsn) { if (item.getId() == id) { return item; } } return null; }// البحث على عنصرفي مكتبة public boolean borrowIte(String memberName, int id) { Member member = findMember(memberName); Item item = findItem(id); if (member == null || item == null) { return false; } //itemsn.remove(item); if (member.addelements(item)) { itemsn.remove(item); } borrowd.add(item);//تسجيل عمليات الاعارة return true; }//طلب اعارة مشروع او كتاب public boolean returnItem(String memberName, int id) { Member member = findMember(memberName); Item item = findborrowditem(id); if (member == null || item == null) { return false; } if (member.returnitem(id, LocalDate.of(2025,7,6))) { itemsn.add(item); } borrowd.remove(item); return true; }//اعادة كتاب او مشروع public List displaProject(String specialization) { List projects = new ArrayList<>(); boolean fuond = false; for (Item i : itemsn) { if (i instanceof Project && i.getSpecialization().equals(specialization)) { projects.add((Project) i); } fuond = true; } if (!fuond) { System.out.println("there are no projects availabel for this type"); } return projects; }//المشاريع المتاحة للغيرمعارة // public void getMembersWithOverdueItems() { boolean found = false; for (Member member : members) { if (member.tiem()) { System.out.println("name:" + member.getName());found=true; } } if(!found) {System.out.println("There are no late members");} }//عرض الاعضاء المتاخرين public List searchItems(String query) { List results = new ArrayList<>(); for (Item item : itemsn) { if (item.getAddress().equals(query) || item.getSpecialization().equals(query)) { results.add(item); } } return results; }//البحث على عنصر من خلال عنوان او النوع public void displaBoook_Member_borro() { for (Member member : members) { System.out.println("name:=" + member.getName()); for (Item i : member.getborrowditem()) { if (i instanceof Book) { Book book = (Book) i; book.printInfo(); } } } System.out.println("there are no members in the library "); }//عرض الاعضاء مع كتب معارة public Item findborrowditem(int id) {//تابع بحث في سجلات الاعارة for (Item item : borrowd) { if (item.getId() == id) { return item; } } return null; }//يحث في سجلات الاعارة public void showMembersWhoBorrowedBookInPeriod(int bookId, LocalDate startDate, LocalDate endDate) { System.out.println("Members who borrowed book ID " + bookId + " between " + startDate + " and " + endDate + ":"); boolean found = false; for (Member member : members) { List borrowedItems = member.getborrowditem(); List borrowDates = member.getBorrowd(); for (int i = 0; i < borrowedItems.size(); i++) { Item item = borrowedItems.get(i); if (item.getId() == bookId) { LocalDate borrowDate = borrowDates.get(i); if ((borrowDate.isEqual(startDate) || borrowDate.isAfter(startDate)) && (borrowDate.isEqual(endDate) || borrowDate.isBefore(endDate))) { System.out.println("Member: " + member.getName() + ", Borrow Date: " + borrowDate + ", Book Title: " + item.getAddress()); found = true; } } } } if (!found) { System.out.println("No members found who borrowed this book in the specified period."); } } } class Member { private int number_of_meber; private String name; List borrowd = new ArrayList<>();//تخزين وقت الاضافة List returnborrowd = new ArrayList<>();//تخزين وقت الارجاع ArrayList itemss = new ArrayList<>();//العناصر المستعارة public List getBorrowd() { return borrowd; } public void setBorrowd(List borrowd) { this.borrowd = borrowd; } public List getReturnborrowd() { return returnborrowd; } public void setReturnborrowd(List returnborrowd) { this.returnborrowd = returnborrowd; } public Member(int number_of_meber, String name) { this.number_of_meber = number_of_meber; this.name = name; } public int getNumber_of_meber() { return number_of_meber; } public void setNumber_of_meber(int number_of_meber) { this.number_of_meber = number_of_meber; } public String getName() { return name; } public void setName(String name) { this.name = name; } public void setItemss(ArrayList itemss) { this.itemss = itemss; } public boolean addelements(Item items) { if (itemss.size() >= 3) { System.out.println("the elements are finish "); return false; } borrowd.add(LocalDate.now()); itemss.add(items); return true; } public boolean returnitem(int id, LocalDate returnDate) { for (Item item : itemss) { int i = itemss.indexOf(item); if (item.getId() == id) { int day = returnDate.getDayOfYear() - borrowd.get(i).getDayOfYear(); returnborrowd.add(returnDate); itemss.remove(item); if (day <= 7 && day >= 0) { System.out.println(day); System.out.println("welcome to our library "); } else { System.out.println("you are late"); } } return true; } return false; } public void printif() { System.out.println("Member{" + "number_of_meber=" + number_of_meber + ", name=" + name + ", borrowd=" + borrowd + ", returnborrowd=" + returnborrowd + "}"); for (Item item : itemss) { System.out.println("{" + "id:=" + item.getId() + ",address:=" + item.getAddress() + ",year_of_publiction:=" + item.getYear_of_publiction() + ",specialization:=" + item.getSpecialization() + "}"); }//k } public ArrayList getborrowditem() { return itemss; } public boolean tiem() { for (int i = 0; i < returnborrowd.size(); i++) { int day = returnborrowd.get(i).getDayOfYear() - borrowd.get(i).getDayOfYear(); if (day > 7) //System.out.println(day); { return true; } } return false; } void m() { for (int i = 0; i < returnborrowd.size(); i++) { System.out.println(returnborrowd.get(i)); } } } public class Mohamad_Hamza_Rawyh { public static void main(String[] args) { System.out.println("Hello World!"); Scanner cin = new Scanner(System.in); Library b = new Library(); b.addItem(new Book("Ahmad", 105, "opera", 1, "java", "2005","basic scinces")); b.addItem(new Book("Alaa", 998, "opera", 2, "c++", "2000","intelligence")); b.addItem(new Book("Ebraheem", 788, "opera", 3, "c#", "2020","software")); b.addItem(new Project("ITE","2009",4,"ttt","2000","software")); b.addItem(new Project("UIA","2007",5,"lgf","2018","inteligence")); b.addItem(new Project("SWE","1998",6,"ugp","1999","basic scince")); boolean c = true; boolean i9 = false; while (c) { System.out.println(" ****************************************************************"); System.out.println(" * view_All_Book,enter 1 *"); System.out.println(" * TO disply a Book Member borrowed,enter 2 *"); System.out.println(" * To enter a book or To enter project,enter 3 *"); System.out.println(" * search Items,enter 4 *"); System.out.println(" * To borrow a item,enter 5 *"); System.out.println(" * To return the item,enter 6 *"); System.out.println(" * Third year projects,enter 7 *"); System.out.println(" * TO dispaly all members who borrow the book artifecal,enter 8 *"); System.out.println(" * viwe members of lates,enter 9 *"); System.out.println(" * getCurrentlyBorrowebook,enter 10 *"); System.out.println(" * view all project of specialization,enter 11 *"); System.out.println(" * To enter member ,enter 12 *"); System.out.println(" * To dispaly all members during a specific period,enter 13 *"); System.out.println(" * To exit the program,enter 14 *"); System.out.println(" ****************************************************************"); int M = cin.nextInt(); switch (M) { case 1: b.view_All_Book(); break; case 2: b.displaBoook_Member_borro(); break; case 3: System.out.println("To enter the item"); String item1 = cin.next(); if (item1.equals("book")) { System.out.println(" enter name_of_author:"); String name_of_author = cin.next(); System.out.println(" enter number_of_page:"); int number_of_page = cin.nextInt(); System.out.println("enter publish_hous:"); String publish_hous = cin.next(); System.out.println("enter id:"); int id = cin.nextInt(); System.out.println("enter address "); String address = cin.next(); System.out.println("enter year_of_publiction:"); String year_of_publiction = cin.next(); System.out.println("enter specialization,'\nBASIC SCIENCES,ENTER 1\nINTELLIGENCE,ENTER2\nSOFTWER,ENTER3\nNETWORKS,ENTER 4\n' "); int i = cin.nextInt(); if (i == 1 || i == 2 || i == 3 || i == 4) { String specialization[] = {"BASIC SCIENCES", "INTELLIGENCE", "SOFTWER", "NETWORKS"}; String s = specialization[i - 1]; b.addItem(new Book(name_of_author, number_of_page, publish_hous, id, address, year_of_publiction, s)); } } else if (item1.equals("project")) { System.out.println("work_team:"); String work_team = cin.next(); System.out.println("year: '\nTHIRD,ENTER1\nFOURTH,ENTER2\nGRADUATION,ENTER3\n"); int i1 = cin.nextInt(); if (i1 == 1 || i1 == 2 || i1 == 3) { String year[] = {"THIRD", "FOURTH", "GRADUATION"}; String year1 = year[i1 - 1]; System.out.println("enter id:"); int id1 = cin.nextInt(); System.out.println("enter address "); String address1 = cin.next(); System.out.println("enter year_of_publiction:"); String year_of_publiction1 = cin.next(); System.out.println("enter specialization,'\nBASIC SCIENCES,ENTER 1\nINTELLIGENCE,ENTER2\nSOFTWER,ENTER3\nNETWORKS,ENTER 4\n' "); int i = cin.nextInt(); if (i == 1 || i == 2 || i == 3 || i == 4) { String specialization[] = {"BASIC SCIENCES", "INTELLIGENCE", "SOFTWER", "NETWORKS"}; String specialization1 = specialization[i - 1]; b.addItem(new Project(work_team, year1, id1, address1, year_of_publiction1, specialization1)); } else { System.out.println("please check\n"); } } } else { System.out.println("please check\n"); } break; case 4: System.out.println("to enter query,enter:"); String query = cin.next(); for (Item item : b.searchItems(query)) { item.printInfo(); } break; case 5: System.out.println("To borrow a book ,entre name "); String name = cin.next(); System.out.println(" and id item"); int id4 = cin.nextInt(); if (b.borrowIte(name, id4)) { System.out.println("loan successfully compieted"); } else { System.out.println("the loan was not successful"); } break; case 6: System.out.println("To return the item"); System.out.println("to enter name of member"); String name2 = cin.next(); System.out.println("enter id:"); int id5 = cin.nextInt(); if (b.returnItem(name2, id5)) { System.out.println("wlecom to library"); } else { System.out.println("there is an erroe,please chechk"); } break; case 7: for (Item item2 : b.displayThirdYearProject()) { item2.printInfo(); } break; case 8: b.displayMemberWhoBorrowartifecal(); break; case 9: b.getMembersWithOverdueItems(); break; case 10: for (Item item : b.getCurrentlyBorrowebook()) { item.printInfo(); } break; case 11: System.out.println(",entre specialization "); String specialization4 = cin.next(); for (Item i : b.displaProject(specialization4)) { i.printInfo(); } break; case 12: System.out.println("name of member:"); String name1 = cin.next(); System.out.println(" number fo member :"); int id7 = cin.nextInt(); b.addmember(new Member(id7, name1)); break; case 13: System.out.println("startDate:"); System.out.println("enter year:"); int year = cin.nextInt(); System.out.println("enter month:"); int month = cin.nextInt(); System.out.println("enter day:"); int day = cin.nextInt(); System.out.println("\n******\n"); System.out.println("end Date:"); System.out.println("enter year:"); int year1 = cin.nextInt(); System.out.println("enter month:"); int month1 = cin.nextInt(); System.out.println("enter day:"); int day1 = cin.nextInt(); System.out.println("\n******\n"); System.out.println("enter item id :"); int id = cin.nextInt(); b.showMembersWhoBorrowedBookInPeriod(id, LocalDate.of(year, month, day), LocalDate.of(year1, month1, day1)); break; case 14: c = false; break; default: i9 = true; System.out.println("please restart there is an error"); } } cin.close(); } }