Question: Program 3 , Square , will implement a data type Square that represents squares with the x and y coordinates of their upper-left corners and

Program 3, Square, will implement a data type Square that represents squares with the x and y coordinates of their upper-left corners and the length.

The API should be as follows.

Square(double x, double y, double length) //constructor

double area() //returns the area of the square

double perimeter() //returns the perimeter of the square

boolean intersects(Square b) //does this square intersect b? Two squares would intersect if they share one or more common points

boolean contains(Square b) //does this square contain b?

void draw() //draw this square on standard drawing

Note: The program should include a main method to test that it does the following.

Instantiate a Square object whose upper-left corner coordinates and length are given as command-line arguments. It should print out the area and perimeter of the square.

Prompt the user for a second squares upper-left corner coordinates and length, and indicate whether it intersects with the square specified earlier and also whether it contains the square specified earlier.

Provide a pop-up window that displays the two squares.

A sample run would be as follows.

>java Square 0.2 0.7 0.3

The area is 0.09

The perimeter is 1.2

Enter the upper-left coordinates and the length of a square: 0.3 0.6 0.4

It intersects the first square.

It does not contain the first square.

Also a window should pop up that displays both the squares.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!