AP CSA 1.12 Exercise 1: Two Books, One Class

Unit 1: Using Objects and Methods · Lesson 1.12 · Exercise 1

Two Books, One Class

Objects: Instances of Classes. Write real Java, run it, and submit it to be graded against hidden test cases.

Why this one is worth doing

One class, two instances, two separate sets of values. The class is the blueprint and it holds no data of its own, which is the whole idea this lesson is built on.

What to write

  1. The Book class is written for you. Do not change it.
  2. Read a title, a page count, and a second title and page count.
  3. Create two Book objects from those values.
  4. Print each book description on its own line by calling describe() on each object.
  5. Print the total number of pages across both books.

Your program reads

A word, an integer, a word and an integer, each on its own line.

Your program prints

Three lines: the first description, the second description, and the total page count.

Worked examples

These are the cases you can see. There are more you cannot, and they use different values, so an answer that prints these numbers as constants will fail.

Example 1 input
Dune
412
Hamlet
160
Example 1 output
Dune (412p)
Hamlet (160p)
572
Example 2 input
Emma
1
Odyssey
2
Example 2 output
Emma (1p)
Odyssey (2p)
3

Your answer

Main.java

Input for the Run button

Run sends whatever is in the input box below. Submitting runs your program against every test case, including hidden ones with different input.


  

  

Stuck?

Hint 1

new Book(t1, p1) makes one instance. Calling it twice makes two, and they do not share their title or page count.

Hint 2

describe() is called on an object, not on the class: first.describe(), never Book.describe().

Hint 3

The Book class already stores the values. You do not need to print the title yourself, and you must not edit the class.

Where to go next

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]