Verityprep
Question Bank · Unit 1

AP® Computer Science A Using Objects and Methods FRQ

Work through AP Computer Science A free-response questions on Using Objects and Methods, 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 1–10 of 95
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10

Question 1

Free response Using Objects

Given a string name, e.g. "Bob", return a greeting of the form "Hello Bob!".

helloName("Bob") → "Hello Bob!"
helloName("Alice") → "Hello Alice!"
helloName("X") → "Hello X!"

public String helloName(String name) {
}
The answer and the full solution open in a window.

Question 2

Free response Using Objects

Given two strings, a and b, return the result of putting them together in the order abba, e.g. "Hi" and "Bye" returns "HiByeByeHi".

makeAbba("Hi", "Bye") → "HiByeByeHi"
makeAbba("Yo", "Alice") → "YoAliceAliceYo"
makeAbba("What", "Up") → "WhatUpUpWhat"

Complete the method makeAbba below:

public String makeAbba(String a, String b) {
}
The answer and the full solution open in a window.

Question 3

Free response Using Objects

The web is built with HTML strings like "<i>Yay</i>" which draws Yay as italic text. In this example, the "i" tag makes <i> and </i> which surround the word "Yay". Given tag and word strings, create the HTML string with tags around the word, e.g. "<i>Yay</i>".

makeTags("i", "Yay") → "<i>Yay</i>"
makeTags("i", "Hello") → "<i>Hello</i>"
makeTags("cite", "Yay") → "<cite>Yay</cite>"

public String makeTags(String tag, String word) {
}
The answer and the full solution open in a window.

Question 4

Free response Using Objects

Given an "out" string length 4, such as "<<>>", and a word, return a new string where the word is in the middle of the out string, e.g. "<<word>>". Note: use str.substring(i, j) to extract the String starting at index i and going up to but not including index j.

makeOutWord("<<>>", "Yay") → "<<Yay>>"
makeOutWord("<<>>", "WooHoo") → "<<WooHoo>>"
makeOutWord("[[]]", "word") → "[[word]]"

Complete the method makeOutWord below:

public String makeOutWord(String out, String word) {
}
The answer and the full solution open in a window.

Question 5

Free response Using Objects
Given a string, return a new string made of 3 copies of the last 2 chars of the original string. The string length will be at least 2.…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 6

Free response Using Objects
Given a string, return the string made of its first two chars, so the String "Hello" yields "He". If the string is shorter than length 2, return whatever there…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 7

Free response Using Objects
Given a string of even length, return the first half. So the string "WooHoo" yields "Woo". firstHalf("WooHoo")…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 8

Free response Using Objects
Given a string, return a version without the first and last char, so "Hello" yields "ell". The string length will be at least 2.…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 9

Free response Using Objects
Given 2 strings, a and b, return a string of the form short+long+short, with the shorter string on the outside and the longer string on the inside. The strings…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 10

Free response Using Objects
Given 2 strings, return their concatenation, except omit the first char of each. The strings will be at least length 1. nonStart("Hello", "There") →…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1 of 95
Page 1 of 10