home—info—lects—labs—exams—hws
D2L—tutor/PIs—zoom (snow day)
Object120 + its docs—java.lang docs—java.util docs
intro to arrays
acronyms
What is light-amplified stimulated emission radiation?
Why, that's a L.A.S.E.R. of course!
This abbreviation is called an acronym.
In lecture, we saw arrays-of-doubles.
We will apply similar concepts, but using an array-of-Strings.
-
Re-download the latest Object120.java.
-
Write a test-method testAcronymize. It should contain at least two other interesting
test cases beyond:
assertEquals( "S.C.U.B.A.", acronymize( new String[]{"Self", "contained", "underwater", "breathing", "apparatus"} ) );
|
(Hint: think along the lines of "An array of size 0, and size 1, and size many.)
-
Write a stub method for acronymize.
Make sure it compiles and runs (and fails) your tests.
-
Complete the body for acronymize.
Think about:
-
What is your “so-far” (accumulator) variable going to be?
- What is its initial value?
- How will you update it, each time through the loop?
-
What is your index variable going to be?
- What is its initial value?
- How will you update it, each time through the loop?
Hint:
The built-in function Character.toUpperCase('z') returns 'Z'.
-
Submit your file to D2L, as lab07a.
-
Bonus task:
Have your main method prompt the user for a sentence,
and then print its acronym.
Repeat this until the user types "quit" as the sentence.
Hints:
home—info—lects—labs—exams—hws
D2L—tutor/PIs—zoom (snow day)
Object120 + its docs—java.lang docs—java.util docs
 This page licensed CC-BY 4.0 Ian Barland Page last generated | Please mail any suggestions (incl. typos, broken links) to ibarland radford.edu |
 |