Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java import java.lang.Math; public class ThePoint { int x,y; public ThePoint(int x, int y) { this.x = x; this.y = y; } //getters and setters

Java

image text in transcribed

import java.lang.Math; public class ThePoint { int x,y; public ThePoint(int x, int y) { this.x = x; this.y = y; } //getters and setters public int getX() { return x; } public void setX(int x) { this.x = x; } public int getY() { return y; } public void setY(int y) { this.y = y; } double distanceFromOrigin(){ double d=Math.sqrt((x*x)+(y*y)); return d; } double distance(int x1,int y1){ double d=Math.sqrt((Math.pow(x-x1,2)+Math.pow(y-y1,2))); return d; } double distance(ThePoint obj){ double d=Math.sqrt((Math.pow(x-obj.x,2)+Math.pow(y-obj.y,2))); return d; } public static void main(String[] args) { //creating point object ThePoint p1=new ThePoint(2,3); ThePoint p2=new ThePoint(4,5); //calling methods System.out.println("distance from origin: "+p1.distanceFromOrigin()); System.out.println("distance from given point: "+p1.distance(7,8)); System.out.println("distance from point instance: "+p1.distance(p2)); } }
a. Design and implement a class called TheRectangle that models a rectangle with its top-left and bottom- right corners points. The TheRectangle class uses two instances of ThePoint class (created in the previous exercise) as its top-left and bottom-right corners points. TheRectangle should contains essential attributes, the basic set of methods b. a constructor that constructs a rectangle with the given its top-left and bottomright corners (tlx, tly, brx, bry) an overloaded constructor that constructs a rectangle with two ThePoint instances a method that calculates the area of the rectangle, a method that calculates distance of the top-left corner from the given TheRectangle instance's top-left corner f. the number of rectangles that are created during the run-time Write a test program that test all the methods defined in the class. C. d. e

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

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

More Books

Students also viewed these Databases questions