Solution:
The basic components of the library are: library items and mechanism for giving books to users.Please find the implementation below.
Implementation:
import java.util.HashMap;
import java.util.Map;
/**
*
*/
/**
* @author Abhinaw.Tripathi
*
*/
class Book
{
private String thAuthor,theTitle,pageCount,year,edition;
public Book(String author,String title,String pages,String yearPublished,String bookEdition)
{
this.edition=bookEdition;
this.thAuthor=author;
this.pageCount=pages;
this.theTitle=title;
this.year=yearPublished;
}
public String getThAuthor() {
return thAuthor;
}
public void setThAuthor(String thAuthor) {
this.thAuthor = thAuthor;
}
public String getTheTitle() {
return theTitle;
}
public void setTheTitle(String theTitle) {
this.theTitle = theTitle;
}
public String getPageCount() {
return pageCount;
}
public void setPageCount(String pageCount) {
this.pageCount = pageCount;
}
public String getYear() {
return year;
}
public void setYear(String year) {
this.year = year;
}
public String getEdition() {
return edition;
}
}
interface LibraryItem
{
public String getID();
public boolean checkOut(String holder);
public String getHolder();
}
class LibraryBook extends Book implements LibraryItem
{
private String theID;
private String theHolder;
public LibraryBook(String author, String title, String pages,String yearPublished, String bookEdition,String id)
{
super(author, title, pages, yearPublished, bookEdition);
theID=id;
}
@Override
public String getID()
{
// TODO Auto-generated method stub
return null;
}
@Override
public boolean checkOut(String holder)
{
// TODO Auto-generated method stub
if(theHolder == null)
{
theHolder=holder;
return true;
}
return false;
}
@Override
public String getHolder() {
// TODO Auto-generated method stub
return theHolder;
}
}
class Library
{
private Map items;
public Library()
{
items=new HashMap();
}
public void add(LibraryItem theItem)
{
items.put(theItem.getID(), theItem);
}
public void checkout(String id,String holder)
{
LibraryItem item=(LibraryItem)items.get(id);
item.checkOut(holder);
}
public String getHolder(String id)
{
LibraryItem item=(LibraryItem)items.get(id);
return item.getHolder();
}
}
public class LibraryManagementTest {
/**
*
*/
public LibraryManagementTest() {
// TODO Auto-generated constructor stub
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Book book=new Book("Abhinaw Tripathi", "Design-Pattern", "100", "2016", "2016");
book.getEdition();
book.getPageCount();
book.getTheTitle();
}
}
The basic components of the library are: library items and mechanism for giving books to users.Please find the implementation below.
Implementation:
import java.util.HashMap;
import java.util.Map;
/**
*
*/
/**
* @author Abhinaw.Tripathi
*
*/
class Book
{
private String thAuthor,theTitle,pageCount,year,edition;
public Book(String author,String title,String pages,String yearPublished,String bookEdition)
{
this.edition=bookEdition;
this.thAuthor=author;
this.pageCount=pages;
this.theTitle=title;
this.year=yearPublished;
}
public String getThAuthor() {
return thAuthor;
}
public void setThAuthor(String thAuthor) {
this.thAuthor = thAuthor;
}
public String getTheTitle() {
return theTitle;
}
public void setTheTitle(String theTitle) {
this.theTitle = theTitle;
}
public String getPageCount() {
return pageCount;
}
public void setPageCount(String pageCount) {
this.pageCount = pageCount;
}
public String getYear() {
return year;
}
public void setYear(String year) {
this.year = year;
}
public String getEdition() {
return edition;
}
}
interface LibraryItem
{
public String getID();
public boolean checkOut(String holder);
public String getHolder();
}
class LibraryBook extends Book implements LibraryItem
{
private String theID;
private String theHolder;
public LibraryBook(String author, String title, String pages,String yearPublished, String bookEdition,String id)
{
super(author, title, pages, yearPublished, bookEdition);
theID=id;
}
@Override
public String getID()
{
// TODO Auto-generated method stub
return null;
}
@Override
public boolean checkOut(String holder)
{
// TODO Auto-generated method stub
if(theHolder == null)
{
theHolder=holder;
return true;
}
return false;
}
@Override
public String getHolder() {
// TODO Auto-generated method stub
return theHolder;
}
}
class Library
{
private Map items;
public Library()
{
items=new HashMap();
}
public void add(LibraryItem theItem)
{
items.put(theItem.getID(), theItem);
}
public void checkout(String id,String holder)
{
LibraryItem item=(LibraryItem)items.get(id);
item.checkOut(holder);
}
public String getHolder(String id)
{
LibraryItem item=(LibraryItem)items.get(id);
return item.getHolder();
}
}
public class LibraryManagementTest {
/**
*
*/
public LibraryManagementTest() {
// TODO Auto-generated constructor stub
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Book book=new Book("Abhinaw Tripathi", "Design-Pattern", "100", "2016", "2016");
book.getEdition();
book.getPageCount();
book.getTheTitle();
}
}
No comments:
Post a Comment