CH10 – Attributes

  1. If you haven’t completed Point Objects, do so now.
  2. Add the following lines to the main.
System.out.println(blank.x + "," + blank.y);
int sum = blank.x * blank.x + blank.y * blank.y;
System.out.println(sum);
  1. Compile and run the program.
$ javac PointObject.java
$ java PointObject
java.awt.Point[x=3,y=4]
3,4
25

The completed class should appear as follows.

import java.awt.Point;
public class PointObject {
  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);
  }
}