Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please solve the assignment with all details Code in Java please write code and add comments Important: Apply good programming practices: - Provide comments in
please solve the assignment with all details
Important: Apply good programming practices: - 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_YourId). 1. Introduction: An axis-aligned rectangle can be represented by the position (x,y) of its upper left corner and its dimensions (width and height). This can be illustrated in a Windows coordinate system as shown in Figure 1. Any two distinct points in a plane determine a line, which has an equation determined by the coordinates of the points. The Figure 2 shows a line passing through the points (0,yl) and (100,y2), and illustrates its traditional equation. Figure 2: Traditional equation for the given line Figure 2 shows three types of a position of an axis-aligned rectangle relative to a line passing through the points (0,y1) and (100,y2). The blue rectangle intersects with the line. The green doesn't intersect with the line and it is above the line. The orange rectangle doesn't intersect with the line and it is below the line. Figure 3: Position of a rectangle relative to a line 2. To Do: Write a Java program that given an inpat file containing the coordinates of any number of rectangles, two given ordinates yl and y2 of the line passing through the points (0,y1) and (100,y2), determines the position of the rectangles relative to the given line. Your program should ask the user to enter the ordinates yl and y 2 of the given line. The program should display a table which includes information abeut the position of each rectangle in the file and the relative position to the given line. Finally, it should indicate the slope of the given line (value m of the line equation). See the sample runs. 3. Additional requirements: 1. The ordinates should be positive. Keep reading if the user caters invalid inpot range. 2. The input file contains any number of lines where each line contains 4 doubles separated by *: where the two first represent the coordinates of the upper left and the two last represent the coordinates of the bottom right comer (see Figure 4 for a sample input file, "data. txe"). You may assume that the file includes valid data. 1:5:3:8 e:10:5:40 e:100:3:103.5 Figure 4: 'data txt' 3. Oae tectangle object of type Rectagele2D.Double and one-liae object of type Line2D.Double are constructed enly once. Then just update the location and the dimensions for cach foctangle using Rectangle2D API methods. 4. Use the Libe2D and Rectangle2D AFI (java.awt.geom) methods whenever is applicable. 5. Stop running the program if a given input ordinate type is incorrect. 4. Hinis: - Browse the API Documentation to see all the features of the following classes: Rectangle2D, Line2D. - If the line equation is ymx+b (where m is the sloge of the line) and the cootdinaten of a point is ( xs. ya) then compare yv and mxo tb, for example if yv> mueb then the point is below the line, ete. 5. Sample runs Cannile 1+ Sample 2: Please enter the ordinates y1 and y2 of the given 1 ine: abc Error: It is not double value... Exit Code in Java
please write code and add comments
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