Create a graphical database for a library. It should display the information of
ID: 3820040 • Letter: C
Question
Create a graphical database for a library. It should display the information of every book in the library system. Each book should have the following information: Name Author(s) Year published Publisher ISBN Page Count The system should be able to perform the following operations: Display books in alphabetical order Either all books or the books that met a search criteria noted below Add a book Remove a book Search books based on Name Author Year Publisher ISBN Load a library database file Save a library database fileExplanation / Answer
Based on the above problem statement we will divide the problem statement into the below steps:
Step 01: we will have the entity class for the below fields like
that is as follows:
Name
Author
Year Published
Publisher
ISBN
Pagecount
Find the below code for the step 01:
**************************
package com.sagar.info;
public class Library {
String Name;
String[] Authors;
int YearPublished;
String Publisher;
int ISBN;
int PageCount;
public Library(String name, String[] authors, int yearPublished,
String publisher, int iSBN, int pageCount) {
super();
Name = name;
Authors = authors;
YearPublished = yearPublished;
Publisher = publisher;
ISBN = iSBN;
PageCount = pageCount;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String[] getAuthors() {
return Authors;
}
public void setAuthors(String[] authors) {
Authors = authors;
}
public int getYearPublished() {
return YearPublished;
}
public void setYearPublished(int yearPublished) {
YearPublished = yearPublished;
}
public String getPublisher() {
return Publisher;
}
public void setPublisher(String publisher) {
Publisher = publisher;
}
public int getISBN() {
return ISBN;
}
public void setISBN(int iSBN) {
ISBN = iSBN;
}
public int getPageCount() {
return PageCount;
}
public void setPageCount(int pageCount) {
PageCount = pageCount;
}
}
**********************
Step 02: Each of these fields will be having public getters and setters and using these public getters and setters we will certainly call some methods and use this getters and setters to get and set some values for the operations:
Follow the below code step by stey to get understand at its best
BookShelf.java
****************
package com.sagar.info;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.jar.Attributes.Name;
public class BookShelf {
private ArrayList<Library> bookList = new ArrayList<Library>();
private Library[] collection;
public void addBook(Library book) {
bookList.add(book);
}
public void removeBook(Library book){
bookList.remove(book);
}
Public void loadDatabaseLibraryFile(){
}
public saveDatabaselubraryfile(){
}
public int searchBooks(String Name,String Author,int YearPublished,String Publisher,String ISBN){
//for isbn
for(int i = 0; i <= collection.length; i++){
// check if the current book isbn matches the one provided argument
if (collection[i].getISBN().equals(ISBN))
if(collection[i].getAuthors().equals(Author))
if(collection[i].getName().equals(Name))
if(collection[i].getPublisher().equals(Publisher))
if(collection[i].getYearPublished().equals(YearPublished))
return i;
}
return -1;
}
public ArrayList<Library> bookList(String sortBy) {
ArrayList<Library> list = new ArrayList<Library>(bookList);
SortingComparator comparator = null;
if (sortBy.equals("auther")) {
comparator = new AutherComparator();
} else if (sortBy.equals("bookname")) {
comparator = new BookNameComparator();
}
Collections.sort(list, comparator);
return list;
}}
************
SortingComparator.java
package com.sagar.info;
import java.util.Comparator;
interface SortingComparator extends Comparator<Library> {}
class AutherComparator implements SortingComparator {
@Override
public int compare(Library b1, Library b2) {
return (b1.getName().toUpperCase()).compareTo((b2.getName().toUpperCase()));
}
}
****************************
BookNameComparator.java
package com.sagar.info;
import java.util.Comparator;
class BookNameComparator implements Comparator<Library>,SortingComparator {
@Override
public int compare(Library b1, Library b2) {
return (b1.getName().toUpperCase()).compareTo((b2.getName().toUpperCase()));
}
}
******************************
SortingComparator.java
package com.sagar.info;
import java.util.Comparator;
interface SortingComparator extends Comparator<Library> {}
class AutherComparator implements SortingComparator {
@Override
public int compare(Library b1, Library b2) {
return (b1.getName().toUpperCase()).compareTo((b2.getName().toUpperCase()));
}
}
*******************
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.