Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please code the following in: JAVA! Please use many comments so I can understand. Full points will be awarded, thanks in advance! The LineSegment Class-Class

Please code the following in: JAVA!

Please use many comments so I can understand.

Full points will be awarded, thanks in advance!

image text in transcribedimage text in transcribedimage text in transcribed

The LineSegment Class-Class Composition ("Has a") & Privacy Leaks Find your Point2D.java class that you built in the previous lab. The Point2D should store an x and y coordinate pair, and will be used to build a new class via class composition. A Point2D has a x and a y, while a LineSegment has a start point and an end point (both of which are represented as Point2Ds). This is similar in spirit to your next homework, where we'll build a few simple classes called Money and Date, and then build a meta-class or container class that is composed of both a Money and Date object - we'll call this a Bill object, and we can state that a Bill has a Money and has a Date object inside of it. Note that when a class offers getters/setters for a primitive, pass-by-value ensures that changes to copies of a private primitive won't affect the originalp from methods (as we do with getters and setters), objects are shared due to pass-by-value. This results in a privacy leak: objects you marked as private are still directly accessible due to the memory semantics involved with pass-by-reference. As a result, when we get and set objects, extra care in the form of cloning objects is required to avoid such privacy leaks. In the end, we'll copy our objects and emulate pass-by-value with our objects so that people who try to "get" our private objects actually get a clone of the object - if they destroy the clone, your private state objects will not be affected. Pay special attention to the getters/setters associated with your start and end points; notice how eclipse incorrectly writes this code, too. The LineSegment Class-Class Composition ("Has a") & Privacy Leaks Find your Point2D.java class that you built in the previous lab. The Point2D should store an x and y coordinate pair, and will be used to build a new class via class composition. A Point2D has a x and a y, while a LineSegment has a start point and an end point (both of which are represented as Point2Ds). This is similar in spirit to your next homework, where we'll build a few simple classes called Money and Date, and then build a meta-class or container class that is composed of both a Money and Date object - we'll call this a Bill object, and we can state that a Bill has a Money and has a Date object inside of it. Note that when a class offers getters/setters for a primitive, pass-by-value ensures that changes to copies of a private primitive won't affect the originalp from methods (as we do with getters and setters), objects are shared due to pass-by-value. This results in a privacy leak: objects you marked as private are still directly accessible due to the memory semantics involved with pass-by-reference. As a result, when we get and set objects, extra care in the form of cloning objects is required to avoid such privacy leaks. In the end, we'll copy our objects and emulate pass-by-value with our objects so that people who try to "get" our private objects actually get a clone of the object - if they destroy the clone, your private state objects will not be affected. Pay special attention to the getters/setters associated with your start and end points; notice how eclipse incorrectly writes this code, too

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

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions

Question

Find the probabilities. P (Z Answered: 1 week ago

Answered: 1 week ago