Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

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.

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.

y decreasing from top to bottom

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions