• Post Reply Bookmark Topic Watch Topic
  • New Topic

Aggregating class

 
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: 5162
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?
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!