public class Textbook extends Book
{
private int edition;
public Textbook(String
title, double price, int edition)
{
super(title, price);
this.edition = edition;
}
//getBookInfo() NOTE:
//The Book class doesn't have a getPrice()
method. Sneaky!
//So you must call super's getBookInfo()
method.
public String getBookInfo()
{
return super.getBookInfo() + "-" + edition;
}
public boolean canSubstituteFor(Textbook
other)
{
if (this.getTitle().equals(other.getTitle()))
{
if (edition >= other.getEdition())
{
return true;
}
}
return false;
}
//getEdition() NOTE
//The description of the work
doesn't mention getEdition()
//but it is found in the example
work. So
you must include it.
public int getEdition()
{
return edition;
}
}
|