This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Java in General and the fly likes Aggregating class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Aggregating class" Watch "Aggregating class" New topic
Author

Aggregating class

brent bynum
Greenhorn

Joined: Apr 04, 2012
Posts: 24
3. Create an aggregating class

Write a class called "Line". It should store two Point objects. It should have two
constructors, one that receives 4 ints to set the (x,y) of each end, and the other
that receives two Point objects.

It should have a distance method that computes the length of the line. Its toString
method should print like this: (x,y) to (x,y)

Write a main method that creates a line with each constructor. It should then print
each line and its length.





Output:



I am having the issue with the Point constructor and I am not sure where to go from here.

Any help is appreciated.
Steve Fahlbusch
Bartender

Joined: Sep 18, 2000
Posts: 562
    
    7

ok do you know the difference between integer math and floating point math?
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4531
    
    5

brent bynum, please BeForthrightWhenCrossPostingToOtherSites
http://www.java-forums.org/new-java/78273-aggregating-class.html
http://answers.yahoo.com/question/index?qid=20130616135216AAfAS0A


luck, db
There are no new questions, but there may be new answers.
surlac surlacovich
Ranch Hand

Joined: Mar 12, 2013
Posts: 296

brent bynum wrote:3. Create an aggregating class Write a class called "Line". It should store two Point objects.

Why Point must be aggregated by Line instead of composition, because Point can "live" without Line?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Aggregating class