Question: main class RecMain.java: import java.util.*; public class RecMain { public static void main( String[] RecMain ) { Scanner keyboard = new Scanner( System.in ); System.out.print(

 main class RecMain.java: import java.util.*; public class RecMain { public static

void main( String[] RecMain ) { Scanner keyboard = new Scanner( System.in

); System.out.print( "Enter the two corners of rectangle 1: " ); Rectangle

main class RecMain.java:

import java.util.*; public class RecMain { public static void main( String[] RecMain ) { Scanner keyboard = new Scanner( System.in ); System.out.print( "Enter the two corners of rectangle 1: " ); Rectangle r1 = new Rectangle( keyboard.nextDouble(), keyboard.nextDouble(), keyboard.nextDouble(), keyboard.nextDouble() ); System.out.print( "Enter the two corners of rectangle 2: " ); Rectangle r2 = new Rectangle( keyboard.nextDouble(), keyboard.nextDouble(), keyboard.nextDouble(), keyboard.nextDouble() ); boolean f = r1.disjoint( r2 ); System.out.println( ( f ) ? "The rectangles are disjoint." : "The rectangels intersects." ); System.out.print( "Enter x and y: " ); double x = keyboard.nextDouble(); double y = keyboard.nextDouble(); f = r1.isIn( x, y ); System.out.println( ( f ) ? "The point is in No.1." : "The point is not in No.1." ); if ( !f ) { System.out.printf( "Its distance is %f. ", r1.distance( x, y ) ); } f = r2.isIn( x, y ); System.out.println( ( f ) ? "The point is in No.2." : "The point is not in No.2." ); if ( !f ) { System.out.printf( "Its distance is %f. ", r2.distance( x, y ) ); } } }

The goal of this lab is to write an application for testing whether or not two rectangles intersect. The rectangles are placed on the two-dimensional grad. For each rectangle, the program receives the coordinates of the upper-left and the lower-left corners of the triangle from the user. Then the program receives a point from the user and answers whether the point is in the rectangles, if not the distance of the point from each rectangle. Here are some execution examples of the program: % java RecMain Enter the two corners of rectangle 1:115 5 Enter the two corners of rectangle 2: 3 3 7 7 The rectangles intersect. Enter x and v: 0 5 The point is not in No.1. Its distance is 1.000000 The point is not in No.2. Its distance is 3.000000 % java RecMan Enter the two corners of rectangle 1:115 5 Enter the two corners of rectangle 2: 3 3 7 7 The rectangles intersect. Enter x and v: 4 44 The point is in No.1. The point is in No.2. % java RecMain Enter the two corners of rectangle 1:115 5 Enter the two corners of rectangle 2: 10 10 17 16 The rectangles are disjoint. Enter x and v: 2:3 The point is in No.1. The point is not in No.2. Its distance is 10.630146 The coordinates of the corners of each rectangle are decomposed into two ranges, the range of the x-coordinates and the range of the y-coordinates. For example, a rectangle whose upper-left corner is (4,10) and its lower-right corner is (11, -1) is represented by the x-range [4,11] and the y-range [-1,10

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!