Java
OOP GUIDE / WORK
LINE CLASS SOLUTIONS
Topics
- Aggregation (with no
encapsulation)
TASK – PART 1 & PART
2
No work
TASK –
PART 3 – USING AGGREGATION
Here is my
Line class that uses aggregation:
public class
Line
{
public
Point p1;
public Point p2;
public Line(double x1, double y1, double x2, double y2)
{
p1 = new Point(x1, y1);
p2 = new Point(x2, y2);
}
//We could add instance
methods here...
}
|
TASK –
PART 4 – TESTING THE LINE CLASS
Here is my
Tester class:
public class LineTester
{
public static void
main(String[] args)
{
Line l1 = new Line(3, 6, 2, 0);
System.out.println(l1.p1.x);
System.out.println(l1.p2.y);
l1.p1.y = 12;
}
}
|
|