Implementation

public class Book 
{
    public String title;
    public double price;

    public Book(String bookTitle, double bookPrice){
        this.title = bookTitle;
        this.price = bookPrice;
    }
    public String getTitle(){
        return title;
    }
    
    public String getBookInfo(){
        return title + "-" + price;
    }
// there may be instance variables, constructors, and methods that are not shown
}

Answers

public class Textbook extends Book {
    private int edition;
    private String title;
    private double price;

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

    @Override 
    public String getBookInfo(){
        return super.getBookInfo()+"-"+this.edition;
    } 

    public void EditPrice(double newprice){
        super.price = newprice;
    }
    public void EditTitle(String newTitle){
        super.title = newTitle;
    }

    public void increaseEdition(){
        this.edition ++;
    }
    public static boolean compareBook(Textbook book1, Textbook book2) {
        // Check if both books have non-null titles and compare them
        if (book1 != null && book2 != null) {
            String title1 = book1.getTitle();
            String title2 = book2.getTitle();

            // Use equalsIgnoreCase to perform a case-insensitive comparison
            return title1.equals(title2);
        }
        // If any book is null, they are not the same
        return false;
    }

}

Testing

Textbook txtbk1 = new Textbook(1, "New Textbook V1", 12.99);
Textbook tb2 = new Textbook(1, "AMONGUS", 12.55);
Textbook.compareBook(txtbk1, tb2);
System.out.println(txtbk1.getBookInfo());
txtbk1.EditPrice(12412.123412);
txtbk1.EditTitle("AMONGUS");
txtbk1.increaseEdition();
System.out.println(txtbk1.getBookInfo());

Textbook.compareBook(txtbk1, tb2);
New Textbook V1-12.99-1
AMONGUS-12412.123412-2





true

Textbook txtbk1 = new Textbook(1, “New Textbook V1”, 12.99); System.out.println(txtbk1.getBookInfo()); txtbk1.EditPrice(12412.);123413 txtbk1.EditTitle(“AMONGUS”); txtbk1.increaseEdition(); System.out.println(txtbk1.getBookInfo()); Textbook tb2 = new Textbook(1, “AMONGUS”, 12.55);

Book.c

txtbk1.getTitle();
AMONGUS

Explaining the FRQ:

Classes FRQs can be one of, if not the easiest FRQ in the entire exam. This is primarily because of its brevity and simplicity of knowledge. When you approach this specific problem, you primarily have to write a large amount of code by yourself, and know some of the intricacies of writing classes. Unlike most of the FRQs, this is not very fill-in-the-blank. Thus, when approaching this frq, it is necessary for students to be aware of how methods work, and how to approach certain ideas of classes. Some important things to know from my brief exposure to this type of FRQ are:

    `super`
    `@override`
    public vs private scope
    Setters and getters

By understanding these concepts, students will be successful at this rather easy FRQ.

The Free Response Questions (FRQ) in Advanced Placement (AP) Computer Science represent a pivotal component of the assessment for this challenging course. These FRQs are meticulously designed to evaluate students' deep understanding of advanced programming concepts, algorithmic problem-solving skills, and their ability to apply computational principles to real-world scenarios. AP Computer Science Advanced FRQs typically encompass a wide range of topics, including data structures, dynamic programming, object-oriented design, and more. Students are required to demonstrate not only their coding proficiency but also their capacity to analyze complex problems, devise elegant solutions, and communicate their thought processes effectively. The AP Computer Science Advanced FRQs provide an opportunity for students to showcase their mastery of advanced computer science concepts and showcase their readiness for college-level coursework and future careers in the field of computer science.