You are on page 1of 1

CoorSeg Assignment – Part 1

Remember LineSeg from the last Unit? That class could only handle a line segment with a single number
describing each endpoint on the line segment. We are going to create a new class called CoorSeg (which
takes the place of LineSeg). CoorSeg (for Coordinate segment) will represent a line on the xy coordinate
plane.

Instead of using integers for fields representing the two endpoints, we need an x value and a y value for
each endpoint. For this assignment, you will use a preexisting class in the Java API: the Point class.

For CoorSeg, there will be 2 fields: each of "type" Point (See the Point class in the Java API for details.)

In later assignments, we will add more to your CoorSeg class, but for part 1, you should do the following:

 Create a class called CoorSeg.

 Add an import statement so that you can use the Point class in your class (look up the package you
need to import in the API!)

 Add two fields of type Point to represent the endpoints of your line segment. These will only be the
reference variables. The actual objects will be made in the constructor.

 Add a constructor. For parameters, you will need to include the necessary values to create your two
Point objects.

o Look up constructors in the Point class in the API, to see which constructor that you need
and what information will need to be passed.

o You will not be making Point objects in the Client/Driver class, so don't choose the
constructor which takes another Point object as its parameter.

 Add 4 accessors methods – one for each x and y value for each point. You will need to use accessor
methods from the Point class to get these values inside of your own accessor methods. Don't forget
to check what data types are returned by the accessor methods in the Point class.

 Make a client class CoorSegTester.

o Read in x and values from the user for the two points.

o Create a CoorSeg object using those values.

o Use the accessor methods that you created in CoorSeg to


return and print the individual x and y values for your
CoorSeg object.

You might also like