Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

( Sort the points in a plane ) Write a program that meets the following requirements: Define a class named Point with two data fields

(Sort the points in a plane) Write a program that meets the following requirements:

  • Define a class named Point with two data fields x and y to represent a point's x- and y-coordinates. Implement the Comparable interface for the comparing the points on x-coordinates. If two points have the same x-coordinates, compare their y-coordinates.
  • Define a class named CompareY that implements Comparator. Implement the compare method to compare two points on their y-coordinates. If two points have the same y-coordinates, compare their x-coordinates.
  • Randomly create 100 points and apply the Arrays.sort method to display the points in increasing order of their x-coordinates, and increasing order of their y-coordinates, respectively.

Here is the output for my one hundred random points:

Points sorted on x-coordinates (0.12638188338560674, 50.39020100807109) (1.3859430069979473, 93.03668731421094) (2.6114249850685223, 12.412036459415877) (5.358316988661349, 67.73349416528738) (5.698398128191551, 18.174443182124023) (6.111228516728384, 71.01708527691328) (6.737961380180446, 19.89624406205127) (10.945380525448856, 2.3089433817517158) (11.140972629348767, 56.978256416466955) (11.473717107214354, 8.633772242865334) (11.640945254931045, 50.209029140382945) (11.73062745491189, 24.27451144197278) (12.009138346850644, 51.346768238659465) (14.733275455547734, 62.36450170386685) (16.701927530682802, 63.44897891265917) (16.98085858220256, 41.926524283262204) (17.282403187030347, 46.1644875606277) (17.662721002980785, 75.65237882278792) (19.22903376169922, 38.237568960120925) (20.64644733517309, 37.84374608542981) (21.101662533428865, 7.869029829263086) (21.598291841133722, 2.0344586937058984) (21.708794572145106, 46.692613691134454) (21.768663621231976, 33.34625631624416) (22.590828781819084, 75.53962450489969) (23.49421764853603, 85.67864402753284) (24.72966826901528, 75.55507267675259) (25.34706528930817, 96.0617502144237) (25.945223253198424, 35.65063037849191) (26.19029527281037, 14.68546044795296) (27.15275659487133, 75.27020397834013) (31.965906306324975, 8.142088469615484) (32.18681882406293, 94.69914831921213) (32.525017955625636, 91.39666502162656) (34.174035343003176, 2.6856250934383374) (36.58182037834038, 38.53283959762893) (36.794639762481495, 84.19030510432968) (37.38477265487127, 85.1255094087256) (37.93253085159798, 14.949877900558162) (39.85368095233145, 22.25662218470641) (40.874978954052345, 47.01906562100285) (43.68743245123591, 93.03537619745047) (43.99828472573171, 17.031389873397828) (44.27343271917569, 7.217925457496099) (46.60666648610833, 27.213464364079254) (49.49920336040152, 45.91310249193407) (49.657553180594896, 75.66889174542216) (50.3692898118992, 27.491871363652688) (51.561906095161625, 41.78229172060257) (51.771681315645104, 71.8065214459853) (53.185874418961596, 16.439799775533782) (55.43993416410989, 68.81021804206135) (58.27450917315991, 55.28495614730725) (58.978891013903066, 5.285304281997227) (59.208340345721155, 28.55952182752517) (59.31941924534505, 67.85432400675387) (59.44311189891326, 31.685514504451717) (60.39590256630709, 51.10105409987682) (60.62730542250755, 87.00174949947265) (60.747141393851756, 43.323189018709506) (60.93732003866273, 95.52113828129728) (60.94982026516972, 41.97043801505422) (62.60980405187016, 99.86873119306345) (63.6233226755589, 37.233868147691005) (64.73283317263252, 17.5964923592004) (65.28550151658618, 91.46914646428601) (66.9472019624218, 80.18492819987736) (68.70610068676359, 43.87622835600784) (70.44343015918226, 13.196809202994764) (73.4457010041601, 85.02545398983592) (73.48058506403746, 97.26641846721436) (73.55963309860178, 28.407581473652698) (73.98823875578088, 82.78775861315307) (74.264850983717, 4.885511955377375) (74.68320439076794, 40.997059015543) (75.82801406145458, 1.2204216082105313) (76.28859922430031, 2.9380905204934638) (78.50226659397191, 52.35957996292496) (79.16136845425548, 71.62662382521808) (79.7880202203803, 62.73279095167924) (80.45638512780023, 12.812935689142757) (80.63508877496105, 76.7661570657953) (81.16785716184106, 92.07345267733047) (81.96707638767998, 16.872857384327244) (82.47381100876632, 47.15100371940623) (82.56286540196018, 17.658961834183362) (83.1209702339756, 89.68757485205873) (84.6942377322319, 99.74657112819267) (86.94256423268892, 70.2025070316356) (87.58397094445094, 54.84249751419471) (89.01554076132318, 36.472275987458815) (90.69164070979745, 27.168787793324277) (91.89646892388926, 69.47159792776436) (93.21121081050626, 28.809563963192165) (93.57673785260586, 36.520261070282665) (94.45376557361564, 72.68087037539748) (95.40323879796514, 18.408005368034686) (96.60981354633051, 62.28621678578713) (97.29300228116075, 71.403878963023) (99.4749128960548, 38.96829703839817)

Points sorted on y-coordinates (75.82801406145458, 1.2204216082105313) (21.598291841133722, 2.0344586937058984) (10.945380525448856, 2.3089433817517158) (34.174035343003176, 2.6856250934383374) (76.28859922430031, 2.9380905204934638) (74.264850983717, 4.885511955377375) (58.978891013903066, 5.285304281997227) (44.27343271917569, 7.217925457496099) (21.101662533428865, 7.869029829263086) (31.965906306324975, 8.142088469615484) (11.473717107214354, 8.633772242865334) (2.6114249850685223, 12.412036459415877) (80.45638512780023, 12.812935689142757) (70.44343015918226, 13.196809202994764) (26.19029527281037, 14.68546044795296) (37.93253085159798, 14.949877900558162) (53.185874418961596, 16.439799775533782) (81.96707638767998, 16.872857384327244) (43.99828472573171, 17.031389873397828) (64.73283317263252, 17.5964923592004) (82.56286540196018, 17.658961834183362) (5.698398128191551, 18.174443182124023) (95.40323879796514, 18.408005368034686) (6.737961380180446, 19.89624406205127) (39.85368095233145, 22.25662218470641) (11.73062745491189, 24.27451144197278) (90.69164070979745, 27.168787793324277) (46.60666648610833, 27.213464364079254) (50.3692898118992, 27.491871363652688) (73.55963309860178, 28.407581473652698) (59.208340345721155, 28.55952182752517) (93.21121081050626, 28.809563963192165) (59.44311189891326, 31.685514504451717) (21.768663621231976, 33.34625631624416) (25.945223253198424, 35.65063037849191) (89.01554076132318, 36.472275987458815) (93.57673785260586, 36.520261070282665) (63.6233226755589, 37.233868147691005) (20.64644733517309, 37.84374608542981) (19.22903376169922, 38.237568960120925) (36.58182037834038, 38.53283959762893) (99.4749128960548, 38.96829703839817) (74.68320439076794, 40.997059015543) (51.561906095161625, 41.78229172060257) (16.98085858220256, 41.926524283262204) (60.94982026516972, 41.97043801505422) (60.747141393851756, 43.323189018709506) (68.70610068676359, 43.87622835600784) (49.49920336040152, 45.91310249193407) (17.282403187030347, 46.1644875606277) (21.708794572145106, 46.692613691134454) (40.874978954052345, 47.01906562100285) (82.47381100876632, 47.15100371940623) (11.640945254931045, 50.209029140382945) (0.12638188338560674, 50.39020100807109) (60.39590256630709, 51.10105409987682) (12.009138346850644, 51.346768238659465) (78.50226659397191, 52.35957996292496) (87.58397094445094, 54.84249751419471) (58.27450917315991, 55.28495614730725) (11.140972629348767, 56.978256416466955) (96.60981354633051, 62.28621678578713) (14.733275455547734, 62.36450170386685) (79.7880202203803, 62.73279095167924) (16.701927530682802, 63.44897891265917) (5.358316988661349, 67.73349416528738) (59.31941924534505, 67.85432400675387) (55.43993416410989, 68.81021804206135) (91.89646892388926, 69.47159792776436) (86.94256423268892, 70.2025070316356) (6.111228516728384, 71.01708527691328) (97.29300228116075, 71.403878963023) (79.16136845425548, 71.62662382521808) (51.771681315645104, 71.8065214459853) (94.45376557361564, 72.68087037539748) (27.15275659487133, 75.27020397834013) (22.590828781819084, 75.53962450489969) (24.72966826901528, 75.55507267675259) (17.662721002980785, 75.65237882278792) (49.657553180594896, 75.66889174542216) (80.63508877496105, 76.7661570657953) (66.9472019624218, 80.18492819987736) (73.98823875578088, 82.78775861315307) (36.794639762481495, 84.19030510432968) (73.4457010041601, 85.02545398983592) (37.38477265487127, 85.1255094087256) (23.49421764853603, 85.67864402753284) (60.62730542250755, 87.00174949947265) (83.1209702339756, 89.68757485205873) (32.525017955625636, 91.39666502162656) (65.28550151658618, 91.46914646428601) (81.16785716184106, 92.07345267733047) (43.68743245123591, 93.03537619745047) (1.3859430069979473, 93.03668731421094) (32.18681882406293, 94.69914831921213) (60.93732003866273, 95.52113828129728) (25.34706528930817, 96.0617502144237) (73.48058506403746, 97.26641846721436) (84.6942377322319, 99.74657112819267) (62.60980405187016, 99.86873119306345) Press any key to continue . . .

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

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

Explain the Neolithic age compared to the paleolithic age ?

Answered: 1 week ago

Question

What is loss of bone density and strength as ?

Answered: 1 week ago