2.5 Example: Definition of the class Circle
/*
+-------------+ +-------+
| Circle | +-->| Posn |
+-------------+ | +-------+
| Posn center |--+ | int x |
| int radius | | int y |
+-------------+ +-------+
*/
// to represent a circle
class Circle {
Posn center;
int radius;
Circle(Posn center, int radius) {
this.center = center;
this.radius = radius;
}
}
/* Intreractions:
Examples of the use of the constructor for the class Circle
Circle c1 = new Circle(new Posn(10, 20), 10);
Circle c2 = new Circle(new Posn(20, 40), 15);
Examples of the use of the field selectors for the class Circle
c1.center -- expected: new Posn(10, 20)
c1.radius -- expected: 10
c2.center -- expected: new Posn(20, 40)
c2.radius -- expected: 15
c1.center.x -- expected 10
c1.center.y -- expected 20
c2.center.x -- expected 20
c2.center.y -- expected 40
*/