Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Aggregating class  RSS feed

 
brent bynum
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 605
7
Mac OS X Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok do you know the difference between integer math and floating point math?
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
 
surlac surlacovich
Ranch Hand
Posts: 296
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!