Methods, Math &
String Practice

signatures · Math calls · random ranges · String methods

Task 1: Read a Signature

Pull the method apart before you ever try to call it.

Your Goal

1. Identify the method name in each signature.

2. Count how many parameters each signature has.

3. Describe the parameter types and the return type for each one.

Example Code

Task 2: Write a Matching Call

Move from reading signatures to building a valid call yourself.

Your Goal

1. Write one valid call for each signature.

2. Store the returned value when a method gives one back.

3. Call the void method as a statement by itself.

4. Write your three finished calls in code comments.

Example Code

Task 3: Math Formula

Use several Math calls together to build real expressions.

Your Goal

1. Create a variable named distance for the formula sqrt(rise² + run²).

2. Create a variable named penalty for the formula abs(-4.5) * level.

3. Create a variable named score for the formula pow(abs(rise - run), 2) / level.

4. Print all three results after the formulas are complete.

Example Code

Task 4: Heron's Formula

Use a real geometry formula that depends on several steps.

Your Goal

1. Create three variables for the side lengths 13, 14, and 15.

2. Create a variable named s for the semiperimeter formula (a + b + c) / 2.0.

3. Use the formula sqrt(s(s-a)(s-b)(s-c)) to compute the triangle area.

4. Print the final area.

Task 5: Fix the Return Types

Some method calls fit these variables, and some do not.

Your Goal

1. Inspect every line and decide which variable types are already correct.

2. Repair only the lines whose variable types do not match the returned value.

3. Keep every method call exactly the same.

4. Compile and run only after you finish the fixes.

Example Code

Task 6: Fix a Random Range

Some random formulas almost work, but one tiny detail breaks the range.

Your Goal

1. Inspect each expression and decide whether it really builds the intended integer range.

2. Fix the broken lines without changing the target ranges.

3. Keep any line that is already correct.

Example Code

Task 7: Build Random Ranges

Turn one random double into the exact integer range you need.

Your Goal

1. Create die so it can be any integer from 1 to 6.

2. Create ticket so it can be any integer from 20 to 29.

3. Create room so it can be any integer from 300 to 399.

Example Code

Task 8: Read One String Carefully

Create one extra string, then use one object in several different ways.

Your Goal

1. Create one more String variable with a literal before you begin.

2. Print the length of word.

3. Print the letters from index 2 through index 4.

4. Print everything from index 4 to the end.

5. Print the first location of the letter "o".

6. Decide whether word has the same text as "robotics".

Example Code

Task 9: Compare Words

Use string comparisons to decide sameness and alphabetical order.

Your Goal

1. Create a variable named sameText to test whether first and third have the same text.

2. Create a variable named order to compare first and second alphabetically.

3. Print both variables.

4. Decide which word should appear first in sorted order.

Example Code

Task 10: Build HIDE

Use substring pieces to build a target word in the correct order.

Your Goal

1. Create a new String result using only pieces of original.

2. Make the final printed word become HIDE.

3. Print the finished value of result.

Example Code

Task 11: Decode a Label

Pull several useful pieces out of one compact string.

Your Goal

1. Create a variable named state for the first two letters.

2. Create a variable named number for the middle three digits.

3. Create a variable named section for the last letter.

4. Print all three extracted pieces.

Example Code

Task 12: Pull One Character

Use a one-character substring when a full slice would be too wide.

Your Goal

1. Create a variable named row for the first character.

2. Create a variable named gate for the last character.

3. Keep both results as String values, not chars or numbers.

Example Code

Task 13: Immutable Check

Compare the two lines and figure out what actually changed.

Your Goal

1. Run the program exactly as written.

2. Compare the first printed line and the second printed line.

3. Explain why the original string stayed the same until the new result was saved.

Example Code

Task 14: Escaped Status Card

Mix string concatenation with escape characters to match a target display.

Your Goal

1. Create variables for a student name, a club name, and a rank number.

2. Print the three-line status card shown at the right with one println statement.

3. Use escaped quotes and line breaks so the output matches exactly.

Example Output
"Ava"
Robotics Club
Rank #3

Task 15: Missing or Empty?

A blank string and a missing string do not behave the same way.

Your Goal

1. Predict what each line will do before you run the program.

2. Identify which line is still safe even when the variable does not point to a real string.

3. Fix the broken line so the program can still finish safely.

Example Code
01 / 16