← Unit 3 · all exercises
Saved in this browser only

A box of words

Write a WordBox holding one String. append adds text onto the end of what is stored. length returns how many characters are stored, and get returns the text.

class WordBox { WordBox(String start); void append(String more); int length(); String get(); }

WordBox.java
Loading editor…
Results

Examples

  • WordBox w = new WordBox("ab"); w.append("cd"); w.get() → abcd
  • new WordBox("hello").length() → 5

There are also 3 hidden tests you can't see. Solve the problem, not the examples.