In Java: Fun with Points, Lines, and Composition Define a Point class (Point.java). Your Point class will
Question:
In Java:
Fun with Points, Lines, and Composition
Define a Point class (Point.java). Your Point class will have thefollowing members (and
no others) – variables to hold the x and y values and accessor andmutator functions for
the x and y values. These class members will be declared public andprivate as
appropriate.
Next define a Line class (Line.java). There are a lot of possibleattributes a Line class
could have – name, color, curve, religion, political affiliation,but your line class will have
just four members (and no others), two Point objects (that’scomposition – the Line
class “has a” Point object – actually two, one at each end of theline), and two methods.
One method will calculate the slope of the line and one willcalculate the length of the
line.
I’m sure that you remember the formulas for the slope of a line andthe length of a line,
given the x and y coordinates for two points. But just in case youhave forgotten, Google
is your friend. Look for the distance formula for the length of aline and the slope formula
for the slope of a line. You can use on-line math web sites tocheck your work.
Your final program will be an application (LineTest.java) that willask the user (me) to
input two x and two y values that will define two Points. ThosePoints will be used to
define a line. LineTest.java will then call the Line methods thatcalculate the length and
slope of the line and output those values the screen.
Remember high school geometry when all you students muttered toeach other “Why
are they teaching us this? We will never use this stuff after weleave this class!”. Now
aren’t you glad you were wrong.
I have given you specific instructions as to what code Iexpect your solution to have. I
expect your solution to follow these instructions – no more, noless.
Microeconomics An Intuitive Approach with Calculus
ISBN: 978-0538453257
1st edition
Authors: Thomas Nechyba