JAVA
Part 2 Description
Write a non-static max method for the Point class, which takes a Point parameter p and returns a
new Point object. That new Point object should have an x value which is the maximum of this
point's x and p's x, and a y value which is the maximum of this point's y and p's y. It should not
change the original Point objects. For example:
Point p1 = new Point( 10, 0 );
Point p2 = new Point( 20, -10 );
p1.max( p2 ); // returns a Point at ( 20.0, 0.00 )
Part 2 Starter Code
Copy the following start code into a file called Point.java
public class Point{
private double x;
private double y;
public Point( double x, double y ){
this.x = x;
this.y = y;
}
// YOUR CODE HERE
public String toString(){
return String.format("(%.2f, %.2f)", x, y);
}
}
Point p1 = new Point( 10, 0 );
Point p2 = new Point( 20, -10 );
p1.max( p2 ); // returns a Point at ( 20.0, 0.00 )

JAVA Part 2 Description Write a non-static max method for the Point.pdf

  • 1.
    JAVA Part 2 Description Writea non-static max method for the Point class, which takes a Point parameter p and returns a new Point object. That new Point object should have an x value which is the maximum of this point's x and p's x, and a y value which is the maximum of this point's y and p's y. It should not change the original Point objects. For example: Point p1 = new Point( 10, 0 ); Point p2 = new Point( 20, -10 ); p1.max( p2 ); // returns a Point at ( 20.0, 0.00 ) Part 2 Starter Code Copy the following start code into a file called Point.java public class Point{ private double x; private double y; public Point( double x, double y ){ this.x = x; this.y = y; } // YOUR CODE HERE public String toString(){ return String.format("(%.2f, %.2f)", x, y); } }
  • 2.
    Point p1 =new Point( 10, 0 ); Point p2 = new Point( 20, -10 ); p1.max( p2 ); // returns a Point at ( 20.0, 0.00 )