├── .idea ├── .gitignore ├── vcs.xml ├── misc.xml └── modules.xml ├── src └── library │ ├── enums │ ├── Gender.java │ └── Genre.java │ ├── models │ ├── Database.java │ ├── Book.java │ ├── Reader.java │ └── Library.java │ ├── dao │ ├── LibraryDao.java │ ├── ReaderDao.java │ ├── BookDao.java │ └── impl │ │ ├── LibraryDaoImpl.java │ │ ├── ReaderDaoImpl.java │ │ └── BookDaoImpl.java │ ├── service │ ├── ReaderService.java │ ├── LibraryService.java │ ├── BookService.java │ └── impl │ │ ├── ReaderServiceImpl.java │ │ ├── LibraryServiceImpl.java │ │ └── BookServiceImpl.java │ └── Main.java ├── .gitignore └── ARRAYLIST-TASK-LIBRARY.iml /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /src/library/enums/Gender.java: -------------------------------------------------------------------------------- 1 | package library.enums; 2 | 3 | public enum Gender { 4 | MALE, 5 | FEMALE 6 | } 7 | -------------------------------------------------------------------------------- /src/library/enums/Genre.java: -------------------------------------------------------------------------------- 1 | package library.enums; 2 | 3 | public enum Genre { 4 | EPIC, 5 | EPOC, 6 | NOVEL, 7 | STORY, 8 | SKETCH 9 | 10 | } 11 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/library/models/Database.java: -------------------------------------------------------------------------------- 1 | package library.models; 2 | 3 | import java.util.*; 4 | 5 | public class Database { 6 | public static List libraries = new ArrayList<>(); 7 | public static List books = new ArrayList<>(); 8 | public static List readers = new ArrayList<>(); 9 | } 10 | -------------------------------------------------------------------------------- /src/library/dao/LibraryDao.java: -------------------------------------------------------------------------------- 1 | package library.dao; 2 | 3 | import library.models.Library; 4 | 5 | import java.util.List; 6 | 7 | public interface LibraryDao { 8 | List saveLibrary(Listlibraries); 9 | 10 | ListgetAllLibraries(); 11 | 12 | Library getLibraryById(Long id); 13 | 14 | Library updateLibrary(Long id, Library library); 15 | 16 | String deleteLibrary(Long id); 17 | } 18 | -------------------------------------------------------------------------------- /src/library/dao/ReaderDao.java: -------------------------------------------------------------------------------- 1 | package library.dao; 2 | 3 | import library.models.Reader; 4 | 5 | import java.util.List; 6 | 7 | public interface ReaderDao { 8 | void saveReader(Reader reader); 9 | 10 | List getAllReaders(); 11 | 12 | Reader getReaderById(Long id); 13 | 14 | Reader updateReader(Long id, Reader reader); 15 | 16 | void assignReaderToLibrary(Long readerId,Long libraryId); 17 | } 18 | -------------------------------------------------------------------------------- /src/library/dao/BookDao.java: -------------------------------------------------------------------------------- 1 | package library.dao; 2 | 3 | import library.models.Book; 4 | 5 | import java.util.List; 6 | 7 | public interface BookDao { 8 | Book saveBook(Long libraryId, Book book); 9 | 10 | List getAllBooks(Long libraryId); 11 | 12 | Book getBookById(Long libraryId, Long bookId); 13 | 14 | String deleteBook(Long libraryId,Long bookId); 15 | 16 | void clearBooksByLibraryId(Long libraryId); 17 | } 18 | -------------------------------------------------------------------------------- /src/library/service/ReaderService.java: -------------------------------------------------------------------------------- 1 | package library.service; 2 | 3 | import library.models.Reader; 4 | 5 | import java.util.List; 6 | 7 | public interface ReaderService { 8 | void saveReader(Reader reader); 9 | 10 | List getAllReaders(); 11 | 12 | Reader getReaderById(Long id); 13 | 14 | Reader updateReader(Long id, Reader reader); 15 | 16 | void assignReaderToLibrary(Long readerId,Long libraryId); 17 | } 18 | -------------------------------------------------------------------------------- /src/library/service/LibraryService.java: -------------------------------------------------------------------------------- 1 | package library.service; 2 | 3 | import library.models.Library; 4 | 5 | import java.util.List; 6 | 7 | public interface LibraryService { 8 | 9 | List saveLibrary(Listlibraries); 10 | 11 | ListgetAllLibraries(); 12 | 13 | Library getLibraryById(Long id); 14 | 15 | Library updateLibrary(Long id, Library library); 16 | 17 | String deleteLibrary(Long id); 18 | } 19 | -------------------------------------------------------------------------------- /src/library/service/BookService.java: -------------------------------------------------------------------------------- 1 | package library.service; 2 | 3 | import library.models.Book; 4 | 5 | import java.util.List; 6 | 7 | public interface BookService { 8 | Book saveBook(Long libraryId, Book book); 9 | 10 | List getAllBooks(Long libraryId); 11 | 12 | Book getBookById(Long libraryId, Long bookId); 13 | 14 | String deleteBook(Long libraryId,Long bookId); 15 | 16 | void clearBooksByLibraryId(Long libraryId); 17 | } 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /ARRAYLIST-TASK-LIBRARY.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/library/service/impl/ReaderServiceImpl.java: -------------------------------------------------------------------------------- 1 | package library.service.impl; 2 | 3 | import library.dao.ReaderDao; 4 | import library.dao.impl.ReaderDaoImpl; 5 | import library.models.Reader; 6 | import library.service.ReaderService; 7 | 8 | import java.util.List; 9 | 10 | public class ReaderServiceImpl implements ReaderService { 11 | ReaderDao readerDao = new ReaderDaoImpl(); 12 | @Override 13 | public void saveReader(Reader reader) { 14 | readerDao.saveReader(reader); 15 | } 16 | 17 | @Override 18 | public List getAllReaders() { 19 | return readerDao.getAllReaders(); 20 | } 21 | 22 | @Override 23 | public Reader getReaderById(Long id) { 24 | return readerDao.getReaderById(id); 25 | } 26 | 27 | @Override 28 | public Reader updateReader(Long id, Reader reader) { 29 | return readerDao.updateReader(id, reader); 30 | } 31 | 32 | @Override 33 | public void assignReaderToLibrary(Long readerId, Long libraryId) { 34 | readerDao.assignReaderToLibrary(readerId, libraryId); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/library/models/Book.java: -------------------------------------------------------------------------------- 1 | package library.models; 2 | 3 | import library.enums.Genre; 4 | 5 | public class Book { 6 | private Long bookId; 7 | private String name; 8 | private String author; 9 | private Genre genre; 10 | 11 | 12 | //class 13 | static Long generateId = 1L; 14 | 15 | public Book() { 16 | this.bookId = generateId++; 17 | } 18 | 19 | public Book( String name, String author, Genre genre) { 20 | this.bookId = generateId++; 21 | this.name = name; 22 | this.author = author; 23 | this.genre = genre; 24 | } 25 | 26 | public Long getBookId() { 27 | return bookId; 28 | } 29 | 30 | public void setBookId(Long bookId) { 31 | this.bookId = bookId; 32 | } 33 | 34 | public String getName() { 35 | return name; 36 | } 37 | 38 | public void setName(String name) { 39 | this.name = name; 40 | } 41 | 42 | public String getAuthor() { 43 | return author; 44 | } 45 | 46 | public void setAuthor(String author) { 47 | this.author = author; 48 | } 49 | 50 | public Genre getGenre() { 51 | return genre; 52 | } 53 | 54 | public void setGenre(Genre genre) { 55 | this.genre = genre; 56 | } 57 | 58 | @Override 59 | public String toString() { 60 | return "Book{" + 61 | "bookId=" + bookId + 62 | ", name='" + name + '\'' + 63 | ", author='" + author + '\'' + 64 | ", genre=" + genre + 65 | '}'; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/library/dao/impl/LibraryDaoImpl.java: -------------------------------------------------------------------------------- 1 | package library.dao.impl; 2 | 3 | import library.dao.LibraryDao; 4 | import library.models.Database; 5 | import library.models.Library; 6 | 7 | import java.util.List; 8 | 9 | public class LibraryDaoImpl implements LibraryDao { 10 | 11 | @Override 12 | public List saveLibrary(List libraries) { 13 | Database.libraries.addAll(libraries); 14 | return libraries; 15 | } 16 | 17 | @Override 18 | public List getAllLibraries() { 19 | return Database.libraries; 20 | } 21 | 22 | @Override 23 | public Library getLibraryById(Long id) { 24 | for (Library library : Database.libraries) { 25 | if (id.equals(library.getId())) { 26 | return library; 27 | } 28 | } 29 | return null; 30 | } 31 | 32 | @Override 33 | public Library updateLibrary(Long id, Library library) { 34 | Library s = null; 35 | for (Library l : Database.libraries) { 36 | if (l.getId().equals(id)){ 37 | l.setName(library.getName()); 38 | l.setAddress(library.getAddress()); 39 | s=l; 40 | } 41 | } 42 | return s; 43 | } 44 | 45 | @Override 46 | public String deleteLibrary(Long id) { 47 | for (int i = 0; i < Database.libraries.size(); i++) { 48 | if (Database.libraries.get(i).getId().equals(id)){ 49 | Database.libraries.remove(i); 50 | return "deleted !!"; 51 | } 52 | } 53 | return "not fount !!"; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/library/dao/impl/ReaderDaoImpl.java: -------------------------------------------------------------------------------- 1 | package library.dao.impl; 2 | 3 | import library.dao.ReaderDao; 4 | import library.models.Database; 5 | import library.models.Library; 6 | import library.models.Reader; 7 | 8 | import java.util.List; 9 | 10 | public class ReaderDaoImpl implements ReaderDao { 11 | 12 | @Override 13 | public void saveReader(Reader reader) { 14 | Database.readers.add(reader); 15 | } 16 | 17 | @Override 18 | public List getAllReaders() { 19 | return Database.readers; 20 | } 21 | 22 | @Override 23 | public Reader getReaderById(Long id) { 24 | for (Reader reader : Database.readers) { 25 | if (reader.getId().equals(id)) { 26 | return reader; 27 | } 28 | } 29 | return null; 30 | } 31 | 32 | @Override 33 | public Reader updateReader(Long id, Reader reader) { 34 | for (Reader r : Database.readers) { 35 | if (r.getId().equals(id)) { 36 | r.setEmail(reader.getEmail()); 37 | r.setGender(reader.getGender()); 38 | r.setFullName(reader.getFullName()); 39 | r.setPhoneNumber(reader.getPhoneNumber()); 40 | return r; 41 | } 42 | } 43 | return null; 44 | } 45 | 46 | @Override 47 | public void assignReaderToLibrary(Long readerId, Long libraryId) { 48 | for (Library library : Database.libraries) { 49 | if (library.getId().equals(libraryId)) { 50 | for (Reader reader : Database.readers) { 51 | if (reader.getId().equals(readerId)) { 52 | library.getReaders().add(reader); 53 | System.out.println("Successfully add reader!!"); 54 | break; 55 | } 56 | } 57 | } 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/library/service/impl/LibraryServiceImpl.java: -------------------------------------------------------------------------------- 1 | package library.service.impl; 2 | 3 | import library.dao.impl.LibraryDaoImpl; 4 | import library.models.Database; 5 | import library.models.Library; 6 | import library.service.LibraryService; 7 | 8 | import java.util.List; 9 | 10 | public class LibraryServiceImpl implements LibraryService { 11 | LibraryDaoImpl libraryDao = new LibraryDaoImpl(); 12 | @Override 13 | public List saveLibrary(List libraries) { 14 | if (libraries.isEmpty()){ 15 | try { 16 | throw new RuntimeException("library null!!"); 17 | }catch (RuntimeException e){ 18 | System.out.println(e.getMessage()); 19 | } 20 | } 21 | 22 | libraryDao.saveLibrary(libraries); 23 | return libraries; 24 | } 25 | 26 | @Override 27 | public List getAllLibraries() { 28 | return libraryDao.getAllLibraries(); 29 | } 30 | 31 | @Override 32 | public Library getLibraryById(Long id) { 33 | if (id == null || id <= 0){ 34 | try { 35 | throw new RuntimeException("Invalid id !!"); 36 | } catch (RuntimeException e) { 37 | System.out.println(e.getMessage()); 38 | } 39 | }else { 40 | for (Library library : Database.libraries) { 41 | if (id.equals(library.getId())){ 42 | return libraryDao.getLibraryById(id); 43 | } 44 | } 45 | System.out.println("not fount " + id + " !!"); 46 | } 47 | return null; 48 | } 49 | 50 | @Override 51 | public Library updateLibrary(Long id, Library library) { 52 | return libraryDao.updateLibrary(id, library); 53 | } 54 | 55 | @Override 56 | public String deleteLibrary(Long id) { 57 | return libraryDao.deleteLibrary(id); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/library/models/Reader.java: -------------------------------------------------------------------------------- 1 | package library.models; 2 | 3 | import library.enums.Gender; 4 | 5 | public class Reader { 6 | private Long id; 7 | private String fullName; 8 | private String email; 9 | private String phoneNumber; 10 | private Gender gender; 11 | 12 | 13 | //class 14 | 15 | static Long generateId = 1L; 16 | 17 | 18 | public Reader() { 19 | this.id = generateId++; 20 | } 21 | 22 | public Reader(String fullName, String email, String phoneNumber, Gender gender) { 23 | this.id = generateId++; 24 | this.fullName = fullName; 25 | this.email = email; 26 | this.phoneNumber = phoneNumber; 27 | this.gender = gender; 28 | } 29 | 30 | public Long getId() { 31 | return id; 32 | } 33 | 34 | public void setId(Long id) { 35 | this.id = id; 36 | } 37 | 38 | public String getFullName() { 39 | return fullName; 40 | } 41 | 42 | public void setFullName(String fullName) { 43 | this.fullName = fullName; 44 | } 45 | 46 | public String getEmail() { 47 | return email; 48 | } 49 | 50 | public void setEmail(String email) { 51 | this.email = email; 52 | } 53 | 54 | public String getPhoneNumber() { 55 | return phoneNumber; 56 | } 57 | 58 | public void setPhoneNumber(String phoneNumber) { 59 | this.phoneNumber = phoneNumber; 60 | } 61 | 62 | public Gender getGender() { 63 | return gender; 64 | } 65 | 66 | public void setGender(Gender gender) { 67 | this.gender = gender; 68 | } 69 | 70 | @Override 71 | public String toString() { 72 | return "Reader{" + 73 | "id=" + id + 74 | ", fullName='" + fullName + '\'' + 75 | ", email='" + email + '\'' + 76 | ", phoneNumber='" + phoneNumber + '\'' + 77 | ", gender=" + gender + 78 | '}'; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/library/models/Library.java: -------------------------------------------------------------------------------- 1 | package library.models; 2 | 3 | import java.util.*; 4 | 5 | public class Library { 6 | private Long id; 7 | private String name; 8 | private String address; 9 | private List books = new ArrayList<>(); 10 | private List readers = new ArrayList<>(); 11 | 12 | 13 | //class 14 | static Long generateId = 1L; 15 | 16 | 17 | public Library() { 18 | this.id = generateId++; 19 | } 20 | 21 | public Library(String name, String address, List books, List readers) { 22 | this.id = generateId++; 23 | this.name = name; 24 | this.address = address; 25 | this.books = books; 26 | this.readers = readers; 27 | } 28 | 29 | public Library(String name, String address) { 30 | this.id = generateId++; 31 | this.name = name; 32 | this.address = address; 33 | } 34 | public Library(String name, String address,int s) { 35 | this.name = name; 36 | this.address = address; 37 | } 38 | 39 | public Long getId() { 40 | return id; 41 | } 42 | 43 | public void setId(Long id) { 44 | this.id = id; 45 | } 46 | 47 | public String getName() { 48 | return name; 49 | } 50 | 51 | public void setName(String name) { 52 | this.name = name; 53 | } 54 | 55 | public String getAddress() { 56 | return address; 57 | } 58 | 59 | public void setAddress(String address) { 60 | this.address = address; 61 | } 62 | 63 | public List getBooks() { 64 | return books; 65 | } 66 | 67 | public void setBooks(List books) { 68 | this.books = books; 69 | } 70 | 71 | public List getReaders() { 72 | return readers; 73 | } 74 | 75 | public void setReaders(List readers) { 76 | this.readers = readers; 77 | } 78 | 79 | @Override 80 | public String toString() { 81 | return "Library{" + 82 | "id=" + id + 83 | ", name='" + name + '\'' + 84 | ", address='" + address + '\'' + 85 | ", books=" + books + 86 | ", readers=" + readers + 87 | '}'+"\n"; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/library/dao/impl/BookDaoImpl.java: -------------------------------------------------------------------------------- 1 | package library.dao.impl; 2 | 3 | import library.dao.BookDao; 4 | import library.models.Book; 5 | import library.models.Database; 6 | import library.models.Library; 7 | 8 | import java.util.List; 9 | 10 | public class BookDaoImpl implements BookDao { 11 | @Override 12 | public Book saveBook(Long libraryId, Book book) { 13 | for (Library library : Database.libraries) { 14 | if (library.getId().equals(libraryId)){ 15 | library.getBooks().add( book); 16 | break; 17 | } 18 | } 19 | Database.books.add(book); 20 | return book; 21 | } 22 | 23 | @Override 24 | public List getAllBooks(Long libraryId) { 25 | for (Library library : Database.libraries) { 26 | if (library.getId().equals(libraryId)){ 27 | return library.getBooks(); 28 | } 29 | } 30 | return null; 31 | } 32 | 33 | @Override 34 | public Book getBookById(Long libraryId, Long bookId) { 35 | for (Library library : Database.libraries) { 36 | if (library.getId().equals(libraryId)){ 37 | for (Book book : library.getBooks()) { 38 | if (book.getBookId().equals(bookId)){ 39 | return book; 40 | } 41 | } 42 | break; 43 | } 44 | } 45 | return null; 46 | } 47 | 48 | @Override 49 | public String deleteBook(Long libraryId, Long bookId) { 50 | for (Library library : Database.libraries) { 51 | if (library.getId().equals(libraryId)){ 52 | for (int i = 0; i < library.getBooks().size(); i++) { 53 | if (library.getBooks().get(i).getBookId().equals(bookId)){ 54 | library.getBooks().remove(i); 55 | return "Deleted!!"; 56 | } 57 | } 58 | break; 59 | } 60 | } 61 | return "not fount!!"; 62 | } 63 | 64 | @Override 65 | public void clearBooksByLibraryId(Long libraryId) { 66 | for (Library l : Database.libraries) { 67 | if (l.getId().equals(libraryId)){ 68 | l.getBooks().clear(); 69 | break; 70 | } 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/library/service/impl/BookServiceImpl.java: -------------------------------------------------------------------------------- 1 | package library.service.impl; 2 | 3 | import library.dao.impl.BookDaoImpl; 4 | import library.models.Book; 5 | import library.models.Database; 6 | import library.models.Library; 7 | import library.service.BookService; 8 | 9 | import java.util.List; 10 | 11 | public class BookServiceImpl implements BookService { 12 | BookDaoImpl bookDao = new BookDaoImpl(); 13 | 14 | @Override 15 | public Book saveBook(Long libraryId, Book book) { 16 | try { 17 | if (libraryId == null) { 18 | throw new RuntimeException("library id null!!"); 19 | } else { 20 | boolean t = false; 21 | for (Library library : Database.libraries) { 22 | if (libraryId.equals(library.getId())) { 23 | t = true; 24 | } 25 | } 26 | if (!t) throw new RuntimeException("not fount!!"); 27 | } 28 | if (book.getName() == null) { 29 | throw new RuntimeException("book name null!!"); 30 | } 31 | bookDao.saveBook(libraryId, book); 32 | return book; 33 | } catch (RuntimeException e) { 34 | System.out.println(e.getMessage()); 35 | } 36 | return new Book(); 37 | } 38 | 39 | @Override 40 | public List getAllBooks(Long libraryId) { 41 | try { 42 | if (libraryId == null || 0 > libraryId) { 43 | throw new RuntimeException("Error exception !!"); 44 | } else { 45 | boolean l = true; 46 | for (Library library : Database.libraries) { 47 | if (libraryId.equals(library.getId())) { 48 | l = false; 49 | } 50 | } 51 | if (l) throw new RuntimeException("not fount!!"); 52 | } 53 | return bookDao.getAllBooks(libraryId); 54 | } catch (RuntimeException e) { 55 | System.out.println(e.getMessage()); 56 | } 57 | return null; 58 | } 59 | 60 | @Override 61 | public Book getBookById(Long libraryId, Long bookId) { 62 | try { 63 | if (libraryId == null || libraryId < 0 || bookId == null || bookId < 0) { 64 | throw new RuntimeException("id Error!!"); 65 | } 66 | return bookDao.getBookById(libraryId, bookId); 67 | } catch (RuntimeException e) { 68 | System.out.println(e.getMessage()); 69 | } 70 | return null; 71 | } 72 | 73 | @Override 74 | public String deleteBook(Long libraryId, Long bookId) { 75 | try { 76 | if (libraryId == null || libraryId < 0 || bookId == null || bookId < 0) { 77 | throw new RuntimeException("id Error!!"); 78 | } 79 | bookDao.deleteBook(libraryId, bookId); 80 | } catch (RuntimeException e) { 81 | return e.getMessage(); 82 | } 83 | return "Successfully!!"; 84 | } 85 | 86 | @Override 87 | public void clearBooksByLibraryId(Long libraryId) { 88 | try { 89 | if (libraryId == null || libraryId < 0){ 90 | throw new RuntimeException("Error library id!!"); 91 | } 92 | bookDao.clearBooksByLibraryId(libraryId); 93 | System.out.println("Successfully clear books !"); 94 | }catch (RuntimeException e){ 95 | System.out.println(e.getMessage()); 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/library/Main.java: -------------------------------------------------------------------------------- 1 | package library; 2 | 3 | import library.enums.Gender; 4 | import library.enums.Genre; 5 | import library.models.Book; 6 | import library.models.Library; 7 | import library.models.Reader; 8 | import library.service.impl.BookServiceImpl; 9 | import library.service.impl.LibraryServiceImpl; 10 | import library.service.impl.ReaderServiceImpl; 11 | 12 | import java.util.ArrayList; 13 | import java.util.Scanner; 14 | 15 | public class Main { 16 | static LibraryServiceImpl libraryService = new LibraryServiceImpl(); 17 | static BookServiceImpl bookService = new BookServiceImpl(); 18 | static ReaderServiceImpl readerService = new ReaderServiceImpl(); 19 | 20 | public static void main(String[] args) { 21 | 22 | while (true) { 23 | System.out.print(""" 24 | --------- Welcome to Library -------- 25 | 1.Add library = 26 | 2.Get All library = 27 | 3.Get by id library = 28 | 4.Update library = 29 | 5.Deleted by id library = 30 | 6.Book save = 31 | 7.Get all books = 32 | 8.Get Book By Id = 33 | 9.Delete book = 34 | 10.Clear Books By Library Id = 35 | 11.Save Reader = 36 | 12.Get All Readers = 37 | 13.Get Reader By Id = 38 | 14.Update Reader = 39 | 15.Assign Reader To Library = 40 | 0.Logout > = 41 | ------------------------------------- 42 | """); 43 | System.out.print("choice: "); 44 | String choice = new Scanner(System.in).nextLine(); 45 | switch (choice) { 46 | case "1" -> libraryService.saveLibrary(addLibrary()); 47 | case "2" -> System.out.println(libraryService.getAllLibraries()); 48 | case "3" -> System.out.println(getByIdLibrary()); 49 | case "4" -> System.out.println(libraryService.updateLibrary(updateIdLibrary(), updateLibrary())); 50 | case "5" -> System.out.println(libraryService.deleteLibrary(deleteIdLibrary())); 51 | case "6" -> System.out.println(bookService.saveBook(bookSaveLibraryId(), newBookAdd())); 52 | case "7" -> System.out.println(bookService.getAllBooks(getAllBooksLibraryID())); 53 | case "8" -> System.out.println(bookService.getBookById(updateIdLibrary(), getByBookID())); 54 | case "9" -> System.out.println(bookService.deleteBook(updateIdLibrary(), getByBookID())); 55 | case "10" -> bookService.clearBooksByLibraryId(updateIdLibrary()); 56 | case "11" -> readerService.saveReader(saveReader()); 57 | case "12" -> System.out.println(readerService.getAllReaders()); 58 | case "13" -> System.out.println(readerService.getReaderById(readerId())); 59 | case "14" -> System.out.println(readerService.updateReader(readerId(), saveReader())); 60 | case "15" -> readerService.assignReaderToLibrary(readerId(),updateIdLibrary()); 61 | case "0" -> { 62 | System.out.println("\n Logout..."); 63 | return; 64 | } 65 | default -> { 66 | System.out.println("ERROR choice"); 67 | } 68 | } 69 | } 70 | } 71 | public static Long readerId(){ 72 | System.out.print("write id reader: "); 73 | return new Scanner(System.in).nextLong(); 74 | } 75 | public static Reader saveReader(){ 76 | System.out.print("write full name: "); 77 | String fullName = new Scanner(System.in).nextLine(); 78 | 79 | System.out.print("write email: "); 80 | String email = new Scanner(System.in).nextLine(); 81 | 82 | System.out.print("write phone Number: "); 83 | String phoneNumber = new Scanner(System.in).nextLine(); 84 | 85 | System.out.print("write gender (MALE, FEMALE): "); 86 | String gender = new Scanner(System.in).nextLine().toUpperCase(); 87 | Gender gen = null; 88 | 89 | switch (gender){ 90 | case "MALE" -> gen = Gender.MALE; 91 | case "FEMALE" -> gen = Gender.FEMALE; 92 | default -> System.out.println("Error choice!!"); 93 | } 94 | return new Reader(fullName,email,phoneNumber,gen); 95 | 96 | } 97 | public static Long getByBookID(){ 98 | System.out.print("write id book: "); 99 | return new Scanner(System.in).nextLong(); 100 | } 101 | 102 | 103 | public static Long getAllBooksLibraryID(){ 104 | System.out.print("write id Library: "); 105 | return new Scanner(System.in).nextLong(); 106 | } 107 | 108 | 109 | public static ArrayList addLibrary() { 110 | ArrayList libraries = new ArrayList<>(); 111 | 112 | System.out.print("write name Library: "); 113 | String nameLibrary = new Scanner(System.in).nextLine(); 114 | 115 | System.out.print("write address Library: "); 116 | String addressLibrary = new Scanner(System.in).nextLine(); 117 | 118 | libraries.add(new Library(nameLibrary, addressLibrary)); 119 | 120 | return libraries; 121 | } 122 | 123 | public static Library getByIdLibrary() { 124 | for (Library allLibrary : libraryService.getAllLibraries()) { 125 | System.out.println("id library: " + allLibrary.getId()); 126 | } 127 | System.out.print("write id library:"); 128 | Long id = new Scanner(System.in).nextLong(); 129 | return libraryService.getLibraryById(id); 130 | } 131 | 132 | public static Long updateIdLibrary() { 133 | System.out.print("write library id: "); 134 | return new Scanner(System.in).nextLong(); 135 | } 136 | 137 | public static Library updateLibrary() { 138 | System.out.print("write update Library name: "); 139 | String upLibraryName = new Scanner(System.in).nextLine(); 140 | 141 | System.out.print("write update Library address: "); 142 | String upLibraryAddress = new Scanner(System.in).nextLine(); 143 | 144 | return new Library(upLibraryName, upLibraryAddress,9); 145 | } 146 | public static Long deleteIdLibrary(){ 147 | System.out.print("write id library: "); 148 | return new Scanner(System.in).nextLong(); 149 | } 150 | public static Long bookSaveLibraryId(){ 151 | System.out.print("write id add book Library id: "); 152 | return new Scanner(System.in).nextLong(); 153 | } 154 | public static Book newBookAdd(){ 155 | 156 | System.out.print("write name book: "); 157 | String nameBook = new Scanner(System.in).nextLine(); 158 | 159 | System.out.print("write author name: "); 160 | String authorBook = new Scanner(System.in).nextLine(); 161 | 162 | System.out.print(""" 163 | 1.EPIC, 164 | 2.EPOC, 165 | 3.NOVEL, 166 | 4.STORY, 167 | 5.SKETCH 168 | """); 169 | Genre genre = null; 170 | String choice = new Scanner(System.in).nextLine(); 171 | switch (choice){ 172 | case "1" -> genre = Genre.EPIC; 173 | case "2" -> genre = Genre.EPOC; 174 | case "3" -> genre = Genre.NOVEL; 175 | case "4" -> genre = Genre.STORY; 176 | case "5" -> genre = Genre.SKETCH; 177 | default -> System.out.println("Error choice!!!"); 178 | } 179 | return new Book(nameBook,authorBook,genre); 180 | } 181 | } --------------------------------------------------------------------------------