1. //© A+ Computer Science - www.apluscompsci.com
  2. //Name -
  3. //Date -
  4. //Class -
  5. //Lab -
  6.  
  7. class BoxWord
  8. {
  9. private String word;
  10. public BoxWord() { setWord ( "" ); }
  11. public BoxWord(String s) { setWord ( s ); }
  12. public void setWord(String w) { word = w; }
  13.  
  14. public String toString()
  15. {
  16. if ( word.length () < 2 ) {
  17. return word;
  18. }
  19.  
  20. String output = new String ();
  21. output += word + "\n";
  22.  
  23. for ( int i = 1; i < word.length () - 1; i++ ) {
  24. output += word.charAt ( i );
  25. for ( int j = 0; j < word.length () - 2; j++ )
  26. output += " ";
  27. output += word.charAt ( word.length () - i - 1 ) + "\n";
  28. }
  29.  
  30. StringBuffer buffer = new StringBuffer ( word );
  31. buffer.reverse (); output += buffer.toString () + "\n";
  32. return output;
  33. }
  34. }