Java OOP GUIDE / WORK LINE CLASS 2 SOLUTIONS TASK –
PART 1 – SETUP – LINE CLASS & POINT CLASS No work TASK –
PART 2 – USE ENCAPSULATION ON THE POINT CLASS Here
is my encapsulated Point class:
TASK –
PART 3 – USE ENCAPSULATION ON THE LINE CLASS Here is my
encapsulated Line class:
TASK –
PART 4 – TOSTRING METHODS Here
is my toString() method for the Point class:
Here
is my toString() method for the Line class:
Notice that
in the Line class’ toString() method, when we return p1 and p2 as part of a String
concatenation, we are actually calling the toString()
from the Point class. So that is the
same as: public
String toString() { return p1.toString() + "
to " + p2.toString(); } TASK –
PART 5 – TESTING THE LINE CLASS Do the
following: a)
Create
a Line object that has points (4,2) and (9,1). b)
Output
the Line object to screen. c)
Write
the statement needed to output x1 to screen.
(It should be 4.) d)
Write
the statement needed to change y2 to 13 and then output the line to screen. e)
Output
the first point of the line to screen. f)
Change
p1 so that it is now at (2,3). Output
the line to screen. Here is my
tester class:
|
|||||
|