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 widthwidthwidth 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.

Statement Method 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(); 3 The 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(); 1 The 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(); 1 The 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);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值