Answered step by step
Verified Expert Solution
Question
1 Approved Answer
create a class void draw ( ) / / draw this square on standard drawing.Provide a pop - up window that displays the two squares.
create a class void drawdraw this square on standard drawing.Provide a popup window that displays the two squares. import java.util.Scanner; public class Square private double x; private double y; private double length; Getters and Setters for the private members public double getX return x; public void setXdouble x this.x x; public double getY return y; public void setYdouble y this.y y; public double getLength return length; public void setLengthdouble length this.length length; Constructor public Squaredouble x double y double length this.x x; this.y y; this.length length; To calculate are of square public double area return this.length this.length; To calculate perimeter of Square public double perimeter return length; To check if two squares intersect public boolean intersect Square s double pX this.x; double pY this.y; double pX this.x this.length; double pY this.y this.length; If one rectangle is on left side of other if pX sgetX sgetLength sgetX pX return false; If one rectangle is above other if pY sgetY sgetLength sgetY pY return false; return true; To check if second square is inside another public boolean containsSquare s double pX this.x; double pY this.y; double pX this.x this.length; double pY this.y this.length; double sX sgetX; double sY sgetY; double sX sgetX sgetLength; double sY sgetY sgetLength; ifsX pX && sY pY && sX pX && sY pY return true; return false; public static void mainString args Square s new Square ; System.out.printlnThe area is : sarea; System.out.printlnThe perimeter is : sperimeter; System.out.printlnEnter the upperleft coordinates and the length of a square:"; Scanner scanner new ScannerSystemin; String inputs scanner.nextLinesplit; double a Double.parseDoubleinputs; double b Double.parseDoubleinputs; double c Double.parseDoubleinputs; Square sq new Square abc; ifsintersectsq true System.out.printlnIt intersects the first square"; else System.out.printlnIt doesnot intersects the first square"; ifscontainssq true System.out.printlnIt contains the first square"; else System.out.printlnIt doesnot contain the first square"; scanner.close;
create a class void drawdraw this square on standard drawing.Provide a popup window that displays the two squares. import java.util.Scanner;
public class Square
private double x;
private double y;
private double length;
Getters and Setters for the private members
public double getX
return x;
public void setXdouble x
this.x x;
public double getY
return y;
public void setYdouble y
this.y y;
public double getLength
return length;
public void setLengthdouble length
this.length length;
Constructor
public Squaredouble x double y double length
this.x x;
this.y y;
this.length length;
To calculate are of square
public double area
return this.length this.length;
To calculate perimeter of Square
public double perimeter
return length;
To check if two squares intersect
public boolean intersect Square s
double pX this.x;
double pY this.y;
double pX this.x this.length;
double pY this.y this.length;
If one rectangle is on left side of other
if pX sgetX sgetLength sgetX pX
return false;
If one rectangle is above other
if pY sgetY sgetLength sgetY pY
return false;
return true;
To check if second square is inside another
public boolean containsSquare s
double pX this.x;
double pY this.y;
double pX this.x this.length;
double pY this.y this.length;
double sX sgetX;
double sY sgetY;
double sX sgetX sgetLength;
double sY sgetY sgetLength;
ifsX pX && sY pY && sX pX && sY pY
return true;
return false;
public static void mainString args
Square s new Square ;
System.out.printlnThe area is : sarea;
System.out.printlnThe perimeter is : sperimeter;
System.out.printlnEnter the upperleft coordinates and the length of a square:";
Scanner scanner new ScannerSystemin;
String inputs scanner.nextLinesplit;
double a Double.parseDoubleinputs;
double b Double.parseDoubleinputs;
double c Double.parseDoubleinputs;
Square sq new Square abc;
ifsintersectsq true
System.out.printlnIt intersects the first square";
else
System.out.printlnIt doesnot intersects the first square";
ifscontainssq true
System.out.printlnIt contains the first square";
else
System.out.printlnIt doesnot contain the first square";
scanner.close;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started