Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Provide comments in your code. Provide a program design Use meaningful variables and constant names. Include your name, university id and section number as a

Provide comments in your code.
Provide a program design
Use meaningful variables and constant names.
Include your name, university id and section number as a comment at the beginning of your code.
Submit to Moodle the compressed file of your entire project (HW1_Yourld).
Introduction:
An axis-aligned rectangle can be represented by the position (x,y) of its upper left corner and its dimensions
(width and height). Figure 1 illustrates an axis-aligned rectangle in a Windows coordinate system where the x-
axis pointing to the right (East) and the y-axis pointing down (South).
rigure 1: dxis-diyneu I Eldayle
According to the location of a point from an axis-aligned rectangle, the distance can be calculated as follows:
a) Point inside the rectangle: If the point lies within the boundaries of the rectangle, the distance is simply 0.
b) Point outside the rectangle: This requires considering the four edges of the rectangle and calculating the
minimum distance between the point and each edge. The final distance is the minimum of these four
distances.
Assume you are provided with a text file (data.txt) containing a number of text lines. The first line
contains a comma separated list of 4 decimals representing respectively the position and the dimension
of a given rectangle. The subsequent lines contain records for some points. Each point has two values
x and y. Figure 2 shows a sample of data.txt file.
Figure 2: Sample of data.txt file
To Do:
Write a Java program that given an input file containing a given axis-aligned rectangle and some points, calculates
the distances between the given rectangle and each of those points. The program should display a table which
includes information about the given rectangle and the distances of the points that are outside the rectangle. For
each point outside the rectangle indicate the edge (North, East, West, South) of the rectangle that has been used to
calculate the distance. You program should display the number of points inside the rectangle. See the sample runs.
Additional requirements:
You can assume that there are no errors in the input file.
If the minimum distance between a point and two or more edges of a rectangle is equal, then select
according to your choice one of these edges and consider it as the edge used to calculate the distance
between the point and the rectangle.
A rectangle and a point objects are constructed only once. Then just update the location for each point
using Point2D API methods.
Use the Point2D, Line2D and Rectangle2D API (java.awt) methods whener is applicable.
Hints:
Browse the API Documentation to get familiar with the public interface of the following classes:
Point2D,
Line2D,
Rectangle2D,
String.
Notice that in the java.awt.geom package, the primary class that models a point is Point2D.
The Point2D. Double class represents the point's coordinates with double precision. This apply to
both segment (Line2D/Line2D. Double) and rectangle (Rectangle2D/Rectangle2D. Double).
No need to know how to calculate the distance between a point P and an arbitrary segment AB. There is a
method in the class Line2D that calculates it. Look at it in the API documentation.
Sample runsPlease enter the input file name: data.txt
The given rectangle is located at (5.5,-10.0) and its dimensions (20.0,30.0)
?** Points# **,(x,y)** Edge **, Distance *
Number of points inside the rectangle: 1
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Expert Oracle9i Database Administration

Authors: Sam R. Alapati

1st Edition

1590590228, 978-1590590225

Students also viewed these Databases questions

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago