AP CSA 2022 Q2 - TextBook Class


<-- Back to Solution of Q1 (Game) - FRQ - 2022 Next to Solution of Q3 (ReviewAnalysis) - FRQ - 2022 -->





Solution of Q2 (TextBook) - Free Response Question - 2022


The original question can be found at: https://apcentral.collegeboard.org/media/pdf/ap22-frq-computer-science-a.pdf


Part (a)- public class TextBook extends Book{}


public class TextBook extends Book{
    
    private int edition;

    public TextBook(String bookTitle, double bookPrice, int ed) {
        super(bookTitle, bookPrice);
        edition = ed;
    }
    
    //overriding the Book class method
    public String getBookInfo()
    {
        return super.getBookInfo()+"-"+edition;
    }
    
    public int getEdition()
    {
        return edition;
    }
    
    public boolean canSubstitueFor(TextBook textBook)
    {
        if (super.getTitle().equals(textBook.getTitle()))
        {
            if (edition >= textBook.getEdition()) return true;
            else return false;
        }
        return false;
    }
}


Java project files (with Runner code):


<-- Back to Solution of Q1 (Game) - FRQ - 2022 Next to Solution of Q3 (ReviewAnalysis) - FRQ - 2022 -->