AP Computer Science A • Unit 3.1

Abstraction and Program Design

Detailed answer explanations for the Unit 3.1 multiple-choice practice questions.

Q1B
Q2D
Q3C
Q4A
Q5B
Q6C
Q7A
Q8B
Q9D
Q10A
Q11C
Q12D
How to use this page: First try each question without looking at the explanation. Then compare your answer with the key and read why the other choices are not correct.

Answer Explanations

Q1

A program must represent a delivery, store its destination and status, and allow the status to be updated. Which first-pass design best matches the requirement?

AClass: Destination • Attribute: Delivery • Behavior: status
BClass: Delivery • Attributes: destination, status • Behavior: updateStatus
CClass: Status • Attributes: updateStatus, Delivery • Behavior: none
DClass: Program • Attributes: none • Behavior: destination
Correct answer: B. The thing being represented becomes the class, the values it stores become attributes, and the action it must support becomes a behavior.
Explanation

A first-pass design reads the requirement and sorts its words into three roles. The noun the program is about names the class; the values that describe each one become attributes; the actions the requirement asks for become behaviors. Here the requirement is about a delivery that stores a destination and a status and can have its status updated, so each part lands in exactly one role.

  • A is not correct: it makes Destination the class and Delivery an attribute, which reverses the thing being represented and one of its descriptive values.
  • C is not correct: it lists updateStatus as an attribute even though it is the action the requirement asks for, and it leaves the design with no behavior at all.
  • D is not correct: Program names the whole application rather than the thing being modelled, and it treats destination, a stored value, as a behavior.
Q2

A Route design groups an origin, a destination, and an estimated travel time under one meaningful idea. Which benefit does this illustrate?

AEvery value must be stored as a class variable.
BThe design no longer needs behaviors.
CEach attribute becomes a separate class.
DRelated data can be managed together without exposing every representation detail.
Correct answer: D. Gathering related values under one named idea is what class-level abstraction provides.
Explanation

Abstraction at the class level lets a programmer work with one meaningful idea instead of several loose values. Code that uses a Route can rely on what a route offers without needing to know how each piece is represented inside it.

  • A is not correct: grouping values into a class says nothing about whether any of them is shared across all objects.
  • B is not correct: gathering data together does not remove the need for behaviors; a design normally has both.
  • C is not correct: this is the opposite of grouping, and it would scatter the related values instead of collecting them.
Q3

A requirement mentions a museum and says that each exhibit has a title and room number and can be relocated. Why might Exhibit be selected as a class while Museum is not selected yet?

AThe first noun in every requirement must be ignored.
BOnly nouns that name physical buildings can become classes.
CThe requirement identifies data and behavior for each exhibit but gives the museum no responsibility of its own.
DA program may contain only one class, so the shorter name must be chosen.
Correct answer: C. A noun earns a class when the requirement gives it data to store or behavior to perform; here only the exhibit has both.
Explanation

Not every noun in a requirement becomes a class. The test is whether the requirement assigns that noun a responsibility. The exhibit is given a title, a room number, and the ability to be relocated; the museum is only the setting, so there is nothing yet for a Museum class to hold or do.

  • A is not correct: position in the sentence is not the test; a first noun becomes a class whenever the requirement gives it responsibility.
  • B is not correct: classes are not restricted to physical things, and being a building is neither required nor disqualifying.
  • D is not correct: a program may contain many classes, and name length plays no part in the decision.
Q4

A fitness center creates many Member objects. Each member has a different ID, while one value records the total number of members. Which design is most appropriate?

AMake the ID an instance variable and the total a class variable.
BMake both values class variables.
CMake the ID a class variable and the total an instance variable.
DMake both values unrelated local variables in another method.
Correct answer: A. A value that differs per object is an instance variable; a value shared by the whole class is a class variable.
Explanation

The deciding question is how many copies of the value the design needs. Each member has a different ID, so every object needs its own copy. The total number of members describes the group as a whole, so one shared copy belongs to the class rather than to any individual member.

  • B is not correct: a single shared ID would make every member report the same identifier, which contradicts the requirement that each ID differs.
  • C is not correct: this reverses both decisions, giving one shared ID and a separate total inside every member.
  • D is not correct: local variables disappear when their method ends, so neither value would remain available to the objects that need it.
Q5

A program represents a hiking trail with a name and distance and must be able to mark the trail closed. Which item is a reasonable behavior?

Aname
BmarkClosed
Cdistance
DTrail
Correct answer: B. markClosed names an action the trail can perform, which is what a behavior is.
Explanation

Behaviors are the things an object can do, and their names usually read as actions. Attributes are the values an object stores, and their names usually read as descriptions. Sorting the items in a requirement by that distinction is the core of a first-pass design.

  • A is not correct: name is a value the trail stores, so it belongs among the attributes.
  • C is not correct: distance is also a stored value describing the trail rather than an action it performs.
  • D is not correct: Trail names the class itself, which is neither an attribute nor a behavior.
Q6

A programmer reorganizes the internal steps of formatLabel. Its signature and promised result remain unchanged. Why can existing calls remain unchanged?

ACallers automatically copy the revised method body.
BA method's parameters are ignored after its first call.
CProcedural abstraction lets callers rely on what the method provides rather than every internal step.
DChanging internal steps converts the method into a class variable.
Correct answer: C. A caller depends on the method's signature and promised result, so the body may be reorganized without disturbing it.
Explanation

Procedural abstraction separates what a method promises from how it delivers it. As long as the name, the parameters, and the promised result stay the same, the code that calls the method does not need to know that anything inside it changed. This is what makes a method safe to improve later.

  • A is not correct: a call does not copy the method body; it transfers control to the one definition that exists.
  • B is not correct: parameters are used on every call, not only on the first one.
  • D is not correct: editing a method body does not turn a method into a variable of any kind.
Q7

The following method and calls are used. Which benefit of using a parameter is illustrated?

public static void tag(String t) {
    System.out.println("[" + t + "]");
}

tag("READY");
tag("DONE");
AReuse one named process with different argument values.
BCreate a different method body for each argument.
CRepeat the printing statements in the caller.
DCall the method without providing a value.
Correct answer: A. One method body serves both calls; only the argument changes.
Explanation

A parameter is what lets a single named process work on different values. The method tag is written once and describes the formatting once, and each call supplies the value that formatting should be applied to. Without a parameter the same statements would have to be written again for every value.

  • B is not correct: there is only one method body here, and it is shared by both calls rather than duplicated.
  • C is not correct: repeating the printing statements in the caller is exactly what the parameter avoids.
  • D is not correct: the header declares one parameter, so each call must supply a value for it.
Q8

A Workout design includes the attributes duration and completedSets and the behaviors recordSet and shareWorkout. The requirements mention everything except sharing. Which revision best matches the stated requirements?

ARemove duration.
BRemove shareWorkout.
CReplace recordSet with a title attribute.
DModel each integer as a separate class.
Correct answer: B. shareWorkout is the one item the requirements never ask for, so it is the item to drop.
Explanation

A design should account for what the requirements state and no more. Checking a draft against the requirements works in both directions: every stated need must appear somewhere, and anything that appears without a stated need is a candidate for removal.

  • A is not correct: duration is one of the items the requirements do mention, so removing it would leave a stated need unmet.
  • C is not correct: recordSet is a required behavior, and title is not among the stated needs, so this trades a needed item for an unneeded one.
  • D is not correct: splitting each value into its own class scatters a design that the requirements describe as one workout.
Q9

A method prepares a report by validating data, calculating a result, and formatting a message. Which revision best applies method decomposition?

ARename every variable with a one-letter name.
BMove all three responsibilities into main.
CRepeat the complete report logic wherever it is needed.
DCreate smaller named methods for the separate responsibilities.
Correct answer: D. Decomposition means giving each separate responsibility its own named method.
Explanation

When one method carries several distinct responsibilities, splitting it lets each part be named, understood, and changed on its own. The three tasks described here are independent of one another, which is the signal that they can become three methods.

  • A is not correct: shortening variable names changes nothing about how the responsibilities are divided, and it makes the code harder to read.
  • B is not correct: moving everything into main collects the responsibilities into one place rather than separating them.
  • C is not correct: repeating the logic duplicates all three responsibilities, which is the problem decomposition is meant to remove.
Q10

A program represents a concert ticket. Which pair gives a reasonable attribute and behavior for Ticket?

Aattribute: seatNumber; behavior: changeSeat
Battribute: changeSeat; behavior: seatNumber
Cattribute: Ticket; behavior: class
Dattribute: print; behavior: String
Correct answer: A. seatNumber is a value the ticket stores and changeSeat is an action it can perform.
Explanation

The same sorting rule applies here as in the earlier design questions: descriptive names belong on the attribute side, action names belong on the behavior side. Reading each candidate aloud usually settles which side it belongs on.

  • B is not correct: it swaps the two, listing an action as a stored value and a stored value as an action.
  • C is not correct: Ticket is the class name itself, and class is a reserved word rather than something the ticket does.
  • D is not correct: print names an action rather than a stored value, and String names a type rather than a behavior.
Q11

The same class design is written once as a short description and once as a simplified diagram. Which statement is correct?

AOnly the description may include behaviors.
BOnly the diagram may include attributes.
CBoth can record the same design decisions without being executable code.
DBoth must contain complete declarations and method bodies.
Correct answer: C. A description and a diagram are two ways of writing down the same decisions, and neither one has to run.
Explanation

A design is a record of decisions, not a program. Whether those decisions are written as sentences or drawn as a sketch, they capture the class name, the data, and the behaviors. Choosing between the two forms is a matter of convenience.

  • A is not correct: a diagram can list behaviors just as a description can.
  • B is not correct: a description can list attributes just as a diagram can.
  • D is not correct: requiring complete declarations and method bodies would turn the design into code, which is what a first-pass sketch deliberately avoids.
Q12

Which item should be omitted from a first-pass class-design sketch?

AThe class name
BData required by the problem
CBehaviors required by the problem
DLocal variables and individual implementation statements
Correct answer: D. A first-pass sketch records what the class is and what it must do, not the statements that will eventually carry it out.
Explanation

The point of designing before coding is to settle the large decisions while they are still cheap to change. Local variables and individual statements are implementation details that belong to a later stage; committing to them early makes the sketch harder to revise and hides the structure it is meant to show.

  • A is not correct: the class name is one of the first decisions a sketch is meant to record.
  • B is not correct: the data the problem requires is part of the design, since it determines what each object must store.
  • C is not correct: the behaviors the problem requires are also part of the design, since they determine what each object must be able to do.