Question
Work The goal of this work is to read the dimension of two rectangles ( length and width ) and to compute the distance between
Work
The goal of this work is to read the dimension of two rectangles (length and width) and to compute the distance between them.
1. Create the java project (LabTest_C_yourName_ID) with class main named Test.java. In this file, add the class Rectangle.
2. In the Rectangle class, add two private data members L and w (called dimensions or attributes).
3. In the Rectangle class, add a constructor that uses two parameters LL and ww. When this constructor is used to create an object, it initializes the data of this object by LL and ww.
4. In the Rectangle class, add also a static method called randDimensions() that creates an object R of Rectangle type, initialize their values L and w by random values between 0.0 and 100.0 and returns the object R.
You can use the following statement to generate the random values:
double randomNumber = (Math.random() * ( max-min+1)) + min;
5. In the Rectangle class, add a method distance() that computes and returns the distance between two rectangles R1 and R2 having the values (L1, w1) and (L2, w2) respectively according to the following equation:
d=((L1-L2)^2+(w1-w2)^2 )
Use the following methods sqrt() and pow().
6. Add the display() method that shows the dimensions of a rectangle using class formatter. This method displays also the distance between the two rectangles.
In the method main of the class Test:
6.1. Create an object R1 of the class Rectangle with fixed values LL=17.5 and ww = 21.5
6.2. Create an object R2 of the class Rectangle without fixed values.
6.3. Call the randDimensions () method to initialize R2 with random values.
6.4. Call the display() method to show the dimensions of the rectangles R1 and R2 and the distance between them.
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