Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Marks Work The goal of this work is to read the dimension of two rectangles (length, and width) and to compute the distance between them.

image text in transcribed
Marks 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..yourName. ID) with class main named Test.java. In this file, add the class Rectangle. 2. In the Rectangle dass, add two private data members Land w (called dimensions or attributes). /1 11 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. /1 /1 4. In the Rectangle class, add also a static method called rand Dimensions() that creates an object R of Rectangle type, initialize their values Land 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.randoml) (max-min+1)) + min; 5. In the Rectangle class, add a method distance() that computes and returns the distance between two rectangles RI and R2 having the values (L1, wl) and (L2, W2) respectively according to the following equation: d = (L1-L2) + (w1 - w2)2 Use the following methods sart() 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. /1 11 /1 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 rand Dimensions () method to initialize R2 with random values. /1 11 6.4. Call the display() method to show the dimensions of the rectangles R1 and R2 and the distance between them. 11

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

Databases A Beginners Guide

Authors: Andy Oppel

1st Edition

007160846X, 978-0071608466

More Books

Students also viewed these Databases questions

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago