• 咨询电话 13023111482
  • 犀牛首页
  • IB课程
  • AP课程
  • G5笔面试
  • AMC竞赛
  • HMMT竞赛
  • 物理碗竞赛
犀牛教育
  • AP力学真题
  • AP物理1真题
  • AP物理2真题
  • AP计算机真题
  • AP生物真题
  • AP化学真题
  • AP电磁学真题

AP计算机真题

首页 > AP > AP计算机 > AP计算机真题

2018年AP计算机简答题真题PDF下载

2021-08-10

2018年AP计算机简答题真题PDF下载

1. This question involves reasoning about a simulation of a frog hopping in a straight line. The frog attempts to hop to a goal within a specified number of hops. The simulation is encapsulated in the following FrogSimulation class. You will write two of the methods in this class.

public class FrogSimulation

{

/** Distance, in inches, from the starting position to the goal. */

private int goalDistance;

/** Maximum number of hops allowed to reach the goal. */

private int maxHops;

/** Constructs a FrogSimulation where dist is the distance, in inches, from the starting

* position to the goal, and numHops is the maximum number of hops allowed to reach the goal.

* Precondition: dist > 0; numHops > 0

*/

public FrogSimulation(int dist, int numHops)

{

goalDistance = dist;

maxHops = numHops;

}

/** Returns an integer representing the distance, in inches, to be moved when the frog hops.

*/

private int hopDistance()

{ /* implementation not shown */ }

/** Simulates a frog attempting to reach the goal as described in part (a).

* Returns true if the frog successfully reached or passed the goal during the simulation;

* false otherwise.

*/

public boolean simulate()

{ /* to be implemented in part (a) */ }

/** Runs num simulations and returns the proportion of simulations in which the frog

* successfully reached or passed the goal.

* Precondition: num > 0

*/

public double runSimulations(int num)

{ /* to be implemented in part (b) */ }

}

(a) Write the simulate method, which simulates the frog attempting to hop in a straight line to a goal from the frog's starting position of 0 within a maximum number of hops. The method returns true if the frog successfully reached the goal within the maximum number of hops; otherwise, the method returns false.

The FrogSimulation class provides a method called hopDistance that returns an integer representing the distance (positive or negative) to be moved when the frog hops. A positive distance represents a move toward the goal. A negative distance represents a move away from the goal. The returned distance may vary from call to call. Each time the frog hops, its position is adjusted by the value returned by a call to the hopDistance method.

The frog hops until one of the following conditions becomes true:

  • The frog has reached or passed the goal.
  • The frog has reached a negative position.
  • The frog has taken the maximum number of hops without reaching the goal.

The following example shows a declaration of a FrogSimulation object for which the goal distance is 24 inches and the maximum number of hops is 5. The table shows some possible outcomes of calling the simulate method.

Complete method simulate below. You must use hopDistance appropriately to receive full credit.

/** Simulates a frog attempting to reach the goal as described in part (a).

* Returns true if the frog successfully reached or passed the goal during the simulation;

* false otherwise.

*/

public boolean simulate()

 

(b) Write the runSimulations method, which performs a given number of simulations and returns the proportion of simulations in which the frog successfully reached or passed the goal. For example, if the parameter passed to runSimulations is 400, and 100 of the 400 simulate method calls returned true, then the runSimulations method should return 0.25.

Complete method runSimulations below. Assume that simulate works as specified, regardless of what you wrote in part (a). You must use simulate appropriately to receive full credit.

/** Runs num simulations and returns the proportion of simulations in which the frog

* successfully reached or passed the goal.

* Precondition: num > 0

*/

public double runSimulations(int num)

2018年AP计算机简答题真题余下省略!


你可能还关注

  1. 2021年AP计算机简答题真题PDF下载 2021-08-10   
    2021年AP计算机简答题真题PDF下载
    详情阅读
  2. 2019年AP计算机简答题真题PDF下载 2021-08-10   
    2019年AP计算机简答题真题PDF下载
    详情阅读
  3. 2017年AP计算机简答题真题PDF下载 2021-08-10   
    2017年AP计算机简答题真题PDF下载
    详情阅读
  4. 2016年AP计算机简答题真题PDF下载 2021-08-10   
    2016年AP计算机简答题真题PDF下载
    详情阅读
  5. 2015年AP计算机简答题真题PDF下载 2021-08-10   
    2015年AP计算机简答题真题PDF下载
    详情阅读

扫码免费下载真题

AP计算机真题

  • 2021年AP计算机简答题真题PDF下载
  • 2019年AP计算机简答题真题PDF下载
  • 2018年AP计算机简答题真题PDF下载
  • 2017年AP计算机简答题真题PDF下载
  • 2016年AP计算机简答题真题PDF下载
  • 2015年AP计算机简答题真题PDF下载
犀牛国际

犀牛国际(X-NEW),由业内多名教学专家共同组建,不乏来自加州理工大学、剑桥大学、清华大学、北京大学、复旦大学、新加坡国立大学等国际一流大学。 其中有博士、硕士的学历老师众多,学术功底扎实,有的已经执教十余年,国际领域经验丰富。

国际学科

  • IB课程辅导
  • AP课程培训
  • A-Level课程培训
  • IGCSE课程辅导

国际竞赛

  • AMC数学竞赛
  • AIME数学竞赛
  • HiMCM竞赛
  • PUMaC竞赛
  • HMMT竞赛
  • 滑铁卢数学竞赛
  • 物理碗竞赛
  • BPhO竞赛
  • BAAO竞赛
  • USNCO竞赛
  • UKCHO竞赛
  • CCC竞赛
  • USABO竞赛
  • BBO竞赛
  • BRAIN BEE

G5笔面试

  • STEP
  • PAT
  • ECAA
  • LNAT
  • MAT
  • TSA
  • NSAA
  • BMAT
  • ENGAA
  • CTMUA
犀牛国际 版权所有 沪ICP备2021004381号-1