package membership;
import video.Video;
import book.Book;
import book.LoanBook;
import book.Loanable;
public abstract class Membership
{
public boolean canBorrow(Loanable item,int nItems)
{
return false;
}
}
package membership;
import book.Loanable;
public class StandardMembership extends Membership
{
private final int nMaxBooks=6;
private final int nMaxVideos = 1;
public String toString()
{
return "Standard";
}
public boolean canBorrow(Loanable item,int nItems) {
return Membership.canBorrow(item,nItems,nMaxBooks,nMaxVideos);
}
}
package membership;
import java.util.Calendar;
import book.LoanBook;
import book.Loanable;
public class OapMembership extends Membership
{
int nMaxVideos = 1;
public boolean canBorrow(Loanable item, int nItems)
{
Calendar presentDay = Calendar.getInstance();
int day = presentDay.get(Calendar.DAY_OF_WEEK);
// if (day == Calendar.SATURDAY || day==Calendar.SUNDAY)
// return false;
if(item instanceof LoanBook)
return true;
if(item instanceof Loanable)
return nItems<nMaxVideos;
return false;
}
public String toString()
{
return "OAP";
}
}
package membership;
import video.Video;
import book.LoanBook;
import book.Loanable;
public class JuniorMembership extends Membership {
private final int nMaxBooks = 1;
private final int nMaxVideos = 0;
public String toString() {
return "Junior";
}
public boolean canBorrow(Loanable item, int nItems) {
return Membership.canBorrow(item,nItems,nMaxBooks,nMaxVideos);
}
}
No comments:
Post a Comment