// file: MoveTest.java // Modified CH program shows object variables, object creation ("instantiation") // and calling methods for objects. // Also shows String concatenation, the length() method of the String class, // and escape sequences \n (newline) and \" (double quote) import java.awt.Rectangle ; // import Rectangle class from "awt" package public class MoveTest { public static void main(String[] args) { // create a Rectangle object and store reference to it in Rectangle // object variable "cerealBox" Rectangle cerealBox = new Rectangle(5, 10, 20, 30) ; // create a String object String s1 = "Printing the rectangle" ; // note: above shows "easy" way to create String objects only. // we could have used the more formal: // String s1 = new String("Printing the rectangle") ; // print the String object "pointed to" by s1 System.out.println(s1) ; // print the Rectangle object System.out.println(cerealBox) ; System.out.println() ; // skip a line // show length() method and concatenation System.out.println("The string s1, \"" + s1 + "\" has " + s1.length() + " characters.\n") ; // move the rectangle (by calling Rectangle method "translate") cerealBox.translate(15, 25); s1 = s1 + " (after moving it)" ; // concatenation again System.out.println(s1); // print the moved rectangle and skip a line System.out.println(cerealBox + "\n") ; // print new s1 and its length System.out.println("The string s1, \"" + s1 + "\" has " + s1.length() + " characters.\n") ; } } /* Program output: Printing the rectangle java.awt.Rectangle[x=5,y=10,width=20,height=30] The string s1, "Printing the rectangle" has 22 characters. Printing the rectangle (after moving it) java.awt.Rectangle[x=20,y=35,width=20,height=30] The string s1, "Printing the rectangle (after moving it)" has 40 characters. */