Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In JAVA Design a class named Point that meets the following requirements: Two data fields x and y for representing a point with getter methods.

In JAVA

Design a class named Point that meets the following requirements:

  • Two data fields x and y for representing a point with getter methods.
  • A no-arg constructor that constructs a point for (0, 0).
  • A constructor that constructs a point with the specified x and y values.
  • Override the equals method. Point p1 is said to be greater than point p2 if p1.x == p2.x and p1.y == p2.y.
  • Implement the Comparable interface and the compareTo method. Point p1 is said to be greater than point p2 if p1.x > p2.x or if p1.x == p2.x and p1.y > p2.y.
  • Override the toString() method to return a string as [x value, y value].

Write a test program that creates a Point object p1 at point (3,4) and another Point object p2 at point (3.4, 1.4). Call the p1s equals method with p2 as its argument and print the result. Call the p2s equals method with p1 as its argument and print the result. Call the p1s compareTo method with p2 as its argument and print the result. Call the p2s compareTo method with p1 as its argument and print the result.

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_2

Step: 3

blur-text-image_3

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 Theory And Applications 27th Australasian Database Conference Adc 20 Sydney Nsw September 28 29 20 Proceedings Lncs 9877

Authors: Muhammad Aamir Cheema ,Wenjie Zhang ,Lijun Chang

1st Edition

3319469215, 978-3319469218

More Books

Students also viewed these Databases questions

Question

What Is Psychology?

Answered: 1 week ago