Sunday, 19 September 2010

Adding video with books to library

Its better to have items...

package item;

public class Item {

    String title_;

    public Item (String title)
    {
        title_ = title;
    }
   
    public boolean isLoanable()
    {
        return false;
    }

    public String details ()
    {
        return "Title:"+title_;
    }

    public String toString()
    {
        return "Title:"+title_;
    }

}

changing the book class

package book;

import item.Item;

public abstract class Book extends Item
{
   
    String author_;
    double  price_;
    int    category_, subCategory_;

    public Book (String title, String author,  double price, int category, int subCategory)
    {
        super(title);
        author_ = author;
        price_ = price;
        category_ = category;
        subCategory_ = subCategory;
    }

    public String getDetails ()
    {
        return "hello:";
    }

    public String toString()
    {
        return super.toString()+"--Author:"+author_+"--price:"+price_+"--Category:"+category_+"--SubCategory:"+subCategory_;
    }
   
    public boolean isLoanable()
    {
        return super.isLoanable(); //by default returns false
    }
}

public class LoanBook extends Book implements Loanable
{
 public LoanBook (String title, String author,  double price, int category, int subCategory)
 {
  super(title,author,price,category,subCategory);
 }

 public boolean canLoan()
 {
  return true;
 }

 public String details ()
 {
  return "Loan: "+super.getDetails();
 }

 public String toString()
 {
  return super.toString() + "--Loanable Book";
 }

    public boolean isLoanable()
    {
        return true;
    }
}

public class LoanBook extends Book implements Loanable
{
 public LoanBook (String title, String author,  double price, int category, int subCategory)
 {
  super(title,author,price,category,subCategory);
 }

 public boolean canLoan()
 {
  return true;
 }

 public String details ()
 {
  return "Loan: "+super.getDetails();
 }

 public String toString()
 {
  return super.toString() + "--Loanable Book";
 }

    public boolean isLoanable()
    {
        return true;
    }
}


package book;

public class ReferenceBook extends Book
{
 public ReferenceBook (String title, String author,  double price, int category, int subCategory)
 {
     super(title,author,price,category,subCategory);
 }

 public boolean canLoan()
 {
  return false;
 }

 public String details ()
 {
  return "Reference: "+super.getDetails();
 }

 public String toString()
 {
  return super.toString()+"--Reference Book";
 }

    public boolean isLoanable()
    {
        return false;
    }
}

No comments:

Post a Comment