Verityprep
Question Bank

AP® Computer Science A FRQ Practice: Free-Response Questions with Solutions

Work through AP Computer Science A free-response questions unit by unit, then check each answer against a worked solution.

Free · no sign-up Open questions need no account. Sign up or log in to open the rest.

Questions 161–170 of 329
  1. 161
  2. 162
  3. 163
  4. 164
  5. 165
  6. 166
  7. 167
  8. 168
  9. 169
  10. 170

Question 161

Free response Unit 3: Class Creation
This question involves tracking player performance during a gaming tournament. The GameTracker class, which you will write, is used to monitor each player's…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 162

Free response Unit 3: Class Creation
This question involves analyzing scoring trends for a competitive challenge. The TrendTracker class, which you will write, is used to track not only the scores…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 163

Free response Unit 3: Class Creation
This question involves the implementation of a zombie plant treatment system that is represented by the ZombiePlant class. A ZombiePlant object is created with…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 164

Free response Unit 3: Class Creation
The CupcakeMachine class, which you will write, represents a cupcake vending machine, an automated machine that dispenses cupcakes. CupcakeMachine objects are…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 165

Free response Unit 3: Class Creation
This question involves the SignedText class, which contains methods that are used to include a signature as part of a string of text. You will write the…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 166

Free response Unit 3: Class Creation
Write the complete SummerSpecial class for a pair of FurnitureItem objects. FurnitureItem provides String getProductID() and double getPrice(). IDs have at…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 167

Free response Unit 3: Class Creation
Write a complete class TemperatureLog that tracks daily temperature readings. Below is a specification table showing how the class should behave: STATEMENT…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 168

Free response Unit 3: Class Creation
Design and implement a complete class Scoreboard that tracks players and their scores in a game. The table below describes the required behavior: STATEMENT…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 169

Free response Unit 3: Class Creation
This question involves the implementation of a music playlist system that is represented by the Playlist class. A Playlist object is created with a parameter…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 170

Free response Unit 3: Class Creation

This question involves the implementation of a vending machine system that is represented by the VendingMachine class. A VendingMachine object is created with two parameters: the price of the item in cents and the initial number of items in stock.

The VendingMachine class provides a constructor and the following methods.

  • purchase, which attempts a purchase and returns the change in cents, or -1 if the purchase fails
  • restock, which adds items to the stock
  • getRevenue, which returns the total revenue collected in cents
  • getStock, which returns the number of items remaining

The following table contains a sample code execution sequence and the corresponding results.

STATEMENTS AND EXPRESSIONSVALUE RETURNEDCOMMENT
VendingMachine vm = new VendingMachine(150, 3);Price is 150 cents per item. 3 items in stock.
vm.getStock()3
vm.getRevenue()0No purchases have been made.
vm.purchase(200)50Paid 200, price is 150, change is 50.
vm.getStock()2One item sold.
vm.getRevenue()150Revenue from one sale.
vm.purchase(100)-1Payment of 100 is less than price of 150.
vm.getStock()2No change, purchase failed.
vm.purchase(150)0Exact change, no money returned.
vm.purchase(200)50
vm.getStock()0All items sold.
vm.getRevenue()450Three successful purchases.
vm.purchase(200)-1Out of stock.
vm.getStock()0
vm.restock(2)Two items added.
vm.getStock()2
vm.purchase(175)25
vm.getRevenue()600Four total successful purchases.

Write the complete VendingMachine class, including the constructor and any required instance variables and methods. Your implementation must meet all specifications and conform to the example.

public class VendingMachine {

}
The answer and the full solution open in a window.
Question 161 of 329
Page 17 of 33