Results 1 to 20 of 65
Thread: LineSegment Class
- 10-11-2009, 09:09 PM #1
Member
- Join Date
- Oct 2009
- Posts
- 49
- Rep Power
- 0
LineSegment Class
Hey guys I am having a hard time creating a class to model a line segment.
This class should include a constructor, accessor and mutator methods. It should also include a method that calculates the length of the line segment, which can be calculated using the distance formula and it also must calculate the midpoint formula. It must also have a class to demonstrate the LineSegment.java class.
I would appreciate it if someone could help me with this task.
thanks
- 10-11-2009, 09:26 PM #2
Member
- Join Date
- Apr 2009
- Posts
- 54
- Rep Power
- 0
Why not start with the constructor. Take a look at this google search
class constructor java - Google Search-
Life is not the worst thing we have ... in a few minutes my coffee is ready.
- 10-11-2009, 09:36 PM #3
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Post what you have tried and explain where you are stuck?
- 10-11-2009, 09:37 PM #4
Member
- Join Date
- Oct 2009
- Posts
- 49
- Rep Power
- 0
public class LineSegment
{
private double x1;
private double x2;
private double y1;
private double y2;
private double length;
public LineSegment( double dX1, double dY1
double dX2, double dY2 ){
x1 = dX1;
x2 = dX2;
y1 = dY1;
y2 = dY2;
}
this is what i have so far
- 10-11-2009, 09:49 PM #5
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Please use code tags next time you post code.
So then get on with it. Realize though that your specs say you need a getLength method not property. You can get the length from the points so no need of storing it.
- 10-11-2009, 09:52 PM #6
Member
- Join Date
- Apr 2009
- Posts
- 54
- Rep Power
- 0
Go on making accessors and mutators
class mutator java - Google Search
class accessor java - Google Search-
Life is not the worst thing we have ... in a few minutes my coffee is ready.
- 10-11-2009, 09:53 PM #7
Member
- Join Date
- Oct 2009
- Posts
- 49
- Rep Power
- 0
public class LineSegment
{
private double x1;
private double x2;
private double y1;
private double y2;
private double length;
public LineSegment( double dX1, double dY1
double dX2, double dY2 ){
x1 = dX1;
x2 = dX2;
y1 = dY1;
y2 = dY2;
}
public setx1(double dX1){
x1 = dX1;
}
public setx2(double dX2){
x2 = dX2;
}
public sety1(double dY1){
y1 = dY1;
}
public sety2(double dY2){
y2 = dY2;
}
public getx1(){
return x1;
}
public getx2(){
return x2;
}
public gety1(){
return y1;
}
public gety2(){
return y2;
}
does this look good so far???Last edited by s_dawg101; 10-11-2009 at 09:54 PM. Reason: not finished
- 10-11-2009, 10:00 PM #8
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
You are incapable of understanding my request about code tags above?
P.S Dude, get on with it.
- 10-11-2009, 10:01 PM #9
Member
- Join Date
- Oct 2009
- Posts
- 49
- Rep Power
- 0
i dont know what those are
-
- 10-11-2009, 10:08 PM #11
Member
- Join Date
- Oct 2009
- Posts
- 49
- Rep Power
- 0
could you give me an example??
- 10-11-2009, 10:20 PM #12
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
- 10-11-2009, 10:25 PM #13
Member
- Join Date
- Apr 2009
- Posts
- 54
- Rep Power
- 0
The code tags are here Java Forums - BB Code List
-
Life is not the worst thing we have ... in a few minutes my coffee is ready.
- 10-11-2009, 10:31 PM #14
Member
- Join Date
- Apr 2009
- Posts
- 54
- Rep Power
- 0
Now, go on making a method that calculates the length of the line segment. For that purpose you should have a distance formula.
methods java - Google Search-
Life is not the worst thing we have ... in a few minutes my coffee is ready.
- 10-11-2009, 10:43 PM #15
Member
- Join Date
- Oct 2009
- Posts
- 49
- Rep Power
- 0
how would you put the square root in there??
- 10-11-2009, 10:47 PM #16
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
See the methods in the Math class.
- 10-11-2009, 11:09 PM #17
Member
- Join Date
- Oct 2009
- Posts
- 49
- Rep Power
- 0
ok i got that done. now what???
- 10-11-2009, 11:14 PM #18
Member
- Join Date
- Oct 2009
- Posts
- 49
- Rep Power
- 0
[code] length = sqrt(pow(x2+x1,2)+pow(y2+y1,2)); [code]
does that look good for the distance formula or does something else need to be added???
- 10-11-2009, 11:19 PM #19
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Does it compile?
- 10-11-2009, 11:23 PM #20
Member
- Join Date
- Apr 2009
- Posts
- 54
- Rep Power
- 0
If you have made methods for the distance and midpoint (and also accessors for these), its time for the last part of the job ... to demonstrate that the class can be used. One way is to add a Main class Main java - Google Search
-
Life is not the worst thing we have ... in a few minutes my coffee is ready.
Similar Threads
-
Child-Class Calling a Method in a Parent-Class
By Blah_ in forum New To JavaReplies: 5Last Post: 09-29-2009, 02:48 AM -
[SOLVED] How to pass information from child class to parent class
By pellebye in forum New To JavaReplies: 7Last Post: 05-06-2009, 12:42 PM -
problem in accessing array values of one class in to jframe class
By cenafu in forum AWT / SwingReplies: 8Last Post: 03-21-2009, 09:34 AM -
Able to find class file in WEB-INF/classes but not after add sub folders in class dir
By vitalstrike82 in forum Web FrameworksReplies: 0Last Post: 05-13-2008, 06:16 AM -
Class Reflection: Finding super class names
By Java Tip in forum java.langReplies: 0Last Post: 04-23-2008, 08:12 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks