/* PointTestbed.java */ /* Here's a class that exercises our Point class. Unlike Point, you can run PointTestbed as a standalone program: every executable Java program is a class that contains a method called main()--which is where execution begins. All PointTestbed does is to create a Point instance (we could make more if we felt like it), set its values, and print them. */ public class PointTestbed { /* here is your mantra for this year--every runnable class you write will have a main() with this signature; we already know what "public" and "void" mean; "main" is the name of the method; "String[] args" means that the parameter to main() is an array of elements of type String (a built-in class in Java), known locally as "args" (the members of the array are the command-line arguments to the program); "static" will take some explaining--as a first pass, let's say that a data member or method marked as static is something that belongs to the class as a whole, rather than to a particular instance */ public static void main(String[] args) { /* ok, let's make a Point; the next line in the code compresses several operations; we could be more verbose and proceed as follows-- first make an "object reference" (a variable that can point to an instance of a class, but doesn't yet)... Point pt; ...and then create an instance of Point (we create an instance of a class by saying "new [classname]()") and assign it to our object reference pt = new Point(); */ Point pt = new Point(); /* call a method of the Point instance; general syntax for invoking a method of an object is [instance].[method]([params] pt.setPoint(5, 89); /* print the values held in the Point instance; for the moment you can take System.out.println() as special printing voodoo (though it's going to turn out to be just another method call); you can pass System.out.println() a simple, double-quote delimited string value; you can also, as in this case, pass it strings and other terms conjoined with "+", and Java will convert everything to string values and concatenate the strings (in this case, Java converts the int values returned by getX() and getY() to strings and concatenates them with the two string literals; a more verbose way to write the line of code after this comment would be: int theX = pt.getX(); int theY = pt.getY(); System.out.println("x and y are " + theX + " and " + theY); /* System.out.println("x and y are " + pt.getX() + " and " + pt.getY()); } }