Hi again
Ive made the IsSqare method but now he asks us to do the Contsains method.
Rectangle class
Suppose we have a Rectangle class that begins:
class Rectangle {
private Point upperLeft; // the upper left corner point
private double height; // the height of the rectangle
private double width; // the width of the rectangle
contains method
Write a contains method that returns true if the point passed in is inside the rectangle
Thats what i wrote :
package assignement01; import java.awt.Point; import java.util.Scanner; /** * * @author mouni */ public class Rectangle { private Point upperLeft; // the upper left corner point private double height; // the height of the rectangle private double width; // the width of the rectangle public static void main(String[] args) { // TODO code application logic here Rectangle r = new Rectangle(); Scanner x = new Scanner(System.in); System.out.print("Enter Rectangle height: "); double height = x.nextDouble(); System.out.print("Enter Rectangle width: "); double width = x.nextDouble(); System.out.print("Enter X Point: "); double xheight = x.nextDouble(); System.out.print("Enter Y Point: "); double ywidth = x.nextDouble(); r.contains(p); p(xheight, ywidth); } public boolean contains(Point p) { boolean answer; double x_ul = upperLeft.getX(); double y_ul = upperLeft.getY(); double x_p = p.getX(); double y_p = p.getY(); if ( (x_ul < x_p && x_p < x_ul + width) && (y_ul - height < y_p && y_p < y_ul) ){ answer = true; System.out.print("The Answer is " + answer); }else { answer = false; System.out.print("The Answer is " + answer); } return answer; } }
THANKS A LOT !!!!