# method return statement is wrong

• 10-18-2010, 10:54 PM
ftrengnr
method return statement is wrong
ok in the end of the print line it is supposed to print the coordinates, area and perimeter of the rectangle it is contained in if any.... maybe im just brain dead at this point but im just not seeing it.... the return of method pointCheck in the main method is where the problem lies. the print is supposed to

3.2 Example Program Execution
Rectangle((1,3),(2,2),area=1,perimeter=4) contained within Rectangle((0,3),(5,0),area=15,perimeter=16)
Point (3,2) contained within Rectangle((0,3),(5,0),area=15,perimeter=16)
__________________________________________________ ______________

Code:

```import java.util.Scanner; public class Project7 {         public static void main(String[] args) {                                 // Use Scanner                 System.out.println("Enter x and y coordinates for first point of rectangle 1:");                                 //create scanner                 Scanner input = new Scanner(System.in);                                 //create variable                 int x1 = input.nextInt();                 int y1 = input.nextInt();                                         Point p1 = new Point(x1, y1);                 System.out.println("Enter x and y coordinates for second point of rectangle 1:");                 int x2 = input.nextInt();                 int y2 = input.nextInt();                 Point p2 = new Point(x2, y2);                 Rectangle R1 = new Rectangle(p1, p2);                                 //get user points for the second rectangle                 System.out.println("Enter x and y coordinates for first point of rectangle 2:");                 int x3 = input.nextInt();                 int y3 = input.nextInt();                 Point p3 = new Point(x3,y3);                                 System.out.println("Enter x and y coordinates for second point of rectangle 2:");                 int x4 = input.nextInt();                 int y4 = input.nextInt();                 Point p4 = new Point(x4,y4);                 Rectangle R2 = new Rectangle(p3,p4);                                 System.out.println("Enter x and y coordinates for point:");                 int x = input.nextInt();                 int y = input.nextInt();                 Point P = new Point(x, y);                                                 System.out.println("Rectangle(" + R1.ToString() +", area = "+R1.getArea()+", perimeter = "                         +R1.getPerimeter()+ ")"+Project7.Comparement(R1, R2) + "\nRectangle(" + R2.ToString() + ", area =  "+R2.getArea()                         +", perimeter = "+R2.getPerimeter()+ " \nPoint "+P.ToString() +Project7.pointCheck(R1, R2, P) );                                                 R1.toString();                 R2.toString();                 P.toString();                         }         public static String Comparement(Rectangle R5, Rectangle R6){                                 if(R5.contains(R6.getTopLeft())&& R5.contains(R6.getBottomRight())){                         return " and contains";                 }                 if(R6.contains(R5.getTopLeft()) && R6.contains(R5.getBottomRight())){                         return " is contained within";                 }                                 return " is seperate from";         }         public static String pointCheck(Rectangle R1, Rectangle R2, Point P){                 if(R1.contains(P)){                         return " is containted within ";                 }                 if(R2.contains(P)){                         return " is contained within ";                 }                 return " is outside both rectangles.";         }                         } class Point {        private int P_x;         private int P_y;                 Point(int x, int y)         {        P_x = x;                 P_y = y;         }                 int getX()         {        return P_x;                }                 int getY()         {        return P_y;         }                 String ToString()         {        //Is pt inside rectangle                                 return "(" + P_x + "," + P_y + ")";         } } class Rectangle {        private Point P_top_left;         private Point P_bottom_right;         private int xL;         private int xS;         private int yL;         private int yS;                         Rectangle(Point P1, Point P2)         {        // Find out P_top_left and P_bottom_left                 //condittionals to find top left and bottom right points                 if(P1.getX() < P2.getX()){                         xS = P1.getX();                         xL = P2.getX();                 }                 else{                         xS = P2.getX();                         xL = P1.getX();                 }                 if(P1.getY()<P2.getY()){                         yS = P1.getY();                         yL = P2.getY();                 }                 else{                         yS = P2.getY();                         yL = P1.getY();                 }                 //set top left and bottom right equal to correct points                 P_top_left = new Point(xS,yL);                 P_bottom_right = new Point (xL,yS);         }                 Point getTopLeft()         {                                 // return top left pt;                 return P_top_left;                         }                 Point getBottomRight()         {                 // return bottom left pt;                 return P_bottom_right;         }                 int getArea()         {        // get top left, bottom right pts and find area                                 //set a width and height variable                 int width = P_bottom_right.getX() - P_top_left.getX();                 int height = P_top_left.getY() - P_bottom_right.getY();                                 //set return to area                 return width * height;         }                 int getPerimeter()         {                 //set a width and height variable                 int width = P_bottom_right.getX() - P_top_left.getX();                 int height = P_top_left.getY() - P_bottom_right.getY();                 int area = 2 * width + 2 * height;                 //set return to perimiter                 return area;         }                 boolean contains(Point p)         {                        boolean contains = true;                 //                 if(p.getX()>=xS && p.getX()<=xL && p.getY() < yL && p.getY()>yS){                 contains = true;                 }                 else{                         contains = false;                 }                                 return contains;         }                 String ToString()         {                 return "(" + P_top_left.getX() + "," + P_top_left.getY()+ ")"+","+" ("+P_bottom_right.getX()+","+P_bottom_right.getY()+")";         } }```
• 10-19-2010, 04:15 AM
Eranga
First of all, please use code tags when you are posting code segments in the forum. Unformated codes are really hard to read.

Secondly, what you've problem in pointCheck method? Did you end up with an error. Provide those details too. Because most of the others don't want to run your code and fix error for you.

Good luck!