Textbook is #2 from the from the 2022 AP Computer Science A Free Response problems.

https://apcentral.collegeboard.org/pdf/ap22-frq-computer-science-a.pdf?course=ap-computer-science-a

Textbook class

public class Textbook extends Book
{
    private int edition;

    public Textbook(String bookTitle, double bookPrice, int edition)
    {
        super(bookTitle, bookPrice);
        this.edition = edition;
    }

    public int getEdition()
    {
        return edition;
    }

    public String getBookInfo()
    {
        return super.getBookInfo() + "-" + edition;
    }
    
    public boolean canSubstituteFor(Textbook otherTextbook)
    {
        return this.getTitle().equals(otherTextbook.getTitle()) &&
                this.getEdition() >= otherTextbook.getEdition();
    }
}

See Class writing order for a technique to respond to AP CS FR that request an entire class.

See Inheritance and polymorphism for details including how to write subclasses.

2022 AP CS Exam Free Response Solutions

Additional resources

Help & comments

Get help from AP CS Tutor Brandon Horn

Comment on TextBook