CH10 – Objects as Parameters

  1. If you haven’t completed Point Objects, do so now.
  2. Open PointObject.java and add the following method.
public static void pointPoint(Point p){
  System.out.println("(" + p.x + ", " + p.y + ")");
}
  1. Add a call to main. The complete class should appear as follows. Note the class contains code from the Attributes exercise as well as this exercise.
import java.awt.Point;
public class PointObject {
  public static void pointPoint(Point p){
    System.out.println("(" + p.x + ", " + p.y + ")");
  }

  public static void main(String[] args){
    Point blank;
    blank = new Point(3,4);
    System.out.println(blank.toString());
    System.out.println(blank.x + "," + blank.y);
    int sum = blank.x * blank.x + blank.y * blank.y;
    System.out.println(sum);
    PointObject.pointPoint(blank);
  }
}
  1. Compile and run the program.
$ javac PointObject.java
$ java PointObject
java.awt.Point[x=3,y=4]
3,4
25
(3, 4)