Data1. (b) Write a class NormedPoint that extends the class PointDouble and implements the interface Comparable.
double myX holds the x value of the ordered pair
double myY holds the y value of the ordered pairConstructor
public PointDouble(double x, double y);
Accessors
double getX() returns the x value
double getY() returns the y value
String toString() returns the x and y coordinates in the form (x,y)
Constructor
public NormedPoint(double
x, double y)
Calls the super constructor
Calls the method getNorm to initialize the data value myNorm
Accessors
String toString() Returns the super
toString and the value of the norm
int compareTo(Object rhs) compares the objects norm to the
rhs's norm and returns the appropriate value
Modifiers
double getNorm()
Calculates the norm and returns this value
norm = Math.sqrt( x2 + y2 )
Data
NormedPoint[] myVertices
Contains the values that represent the corners of the rectangle.
int myNumVertices;
Constructor
public Rectangle(NormedPoint
upperLeft, NormedPoint upperRight,
NormedPoint lowerRight, NormedPoint lowerLeft )
Stores all 4 NormedPoints
in the array Clockwise starting with upperLeft
Accessors
String toString() returns all the vertices in
the rectangle
NormedPoint getMax() Finds and returns the point that is
farthest from the origin.
double calculatePerimeter() calculates and returns the distance
around the rectangle
Private Helper
double getDistance(NormedPoint x, NormedPoint y)
given points (x1,y1)
and (x2,y2) the distance between is
Math.sqrt( (x1-x2)
* (x1-x2) + (y1-y2)*(y1-y2)
)
Assume that M has at least two rows and at least two columns.
numRows >=2 and
numCols >= 2
In the following examples, the values to be summed are shown in bold font for emphasis
Matrix M Result of the call borderSum(M,numRows, numCols)
1 0 2 1 borderSum returns
15
0 1 2 2
2 3 0 4
2 3 0 4 borderSum returns
33
5 0 1 2
3 6 0 4
1 2 3 4
1 2 borderSum returns 10
3 4
Complete method borderSum below.
int BorderSum( int[][] M, int numRows, int numCols )
{