Verityprep
Question Bank · Unit 3

AP® Computer Science A Class Creation Practice Questions

Work through AP Computer Science A practice questions on Class Creation, 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 401–402 of 402
  1. 401
  2. 402

Question 401

Free response Writing Classes

A ReadingTracker object records pages read toward a personal reading goal. A newly constructed tracker is given a positive page goal. The tracker starts with 0 pages read and 0 recorded reading days.

The method read takes a number of pages. If the argument is positive, those pages are added to the total pages read and the number of recorded reading days increases by one. If the argument is not positive, the tracker is unchanged. The method pagesLeft returns the number of additional pages needed to reach the goal, or 0 if the goal has already been reached. The method averagePages returns the average number of pages read per recorded reading day, or 0.0 if there have been no recorded reading days. The method metGoal returns whether the total pages read is at least the goal.

Statements and Expressions Value Returned (blank if no value) Comment
ReadingTracker rt = new ReadingTracker(120);A tracker with goal 120 is created.
rt.pagesLeft()120No pages have been recorded.
rt.read(35);Total pages becomes 35; recorded days becomes 1.
rt.read(0);Non-positive input is ignored.
rt.read(50);Total pages becomes 85; recorded days becomes 2.
rt.averagePages()42.5The average is 85 * 1.0 / 2.
rt.metGoal()falseThe goal has not yet been reached.
rt.read(40);Total pages becomes 125; recorded days becomes 3.
rt.pagesLeft()0No more pages are needed.
rt.metGoal()trueThe total is at least the goal.

Write the complete ReadingTracker class, including all instance variables, a constructor, and all methods described above.

The answer and the full solution open in a window.

Question 402

Free response Writing Classes
Car rental companies rent cars to customers. You will write the complete RentalCarPlan class, which represents an agreement between a car rental company and a…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 401 of 402
Page 41 of 41