Results 1 to 6 of 6
- 03-01-2009, 04:20 AM #1
Member
- Join Date
- Dec 2008
- Posts
- 10
- Rep Power
- 0
Constructor with unknown amount of objects?
Ok, as a project for my programming class i was given te job to create a Point class then creating a circle class and then making a drawing class. This drawing class would consist of multiple circle objects that would then be stored in an array. To be honest i am utterly at a road block as to how make this constructor. i have tried...
No doubt this thinking is VERY flawed, i believe that my Dessin constructor should receive a circle(x coordinates, its y and its radius), and maybe a double to say how many to make.Java Code:import java.util.Scanner; public class Dessin { Scanner scan = new Scanner(System.in); int i; public Dessin(int size) { Cercle[] tab = new Cercle[size]; for (i=0;i<tab.length;i++); { double x=scan.nextDouble(); double y=scan.nextDouble(); double z=scan.nextDouble(); tab[i]=new Cercle(x,y,z); } }
I am up for any suggestions on ways to do this constructor, this is a learning experience so any input on better way of doing things would be appreciated. Thank you
-
I think what's causing you (and me) problems, is that you have no idea how to initialize all of the Circles. How do you know how big they should be? How do you know where they should be located?
Well, were you given any clues about this from your instructor? Are they supposed to be random size and location?
Much luck.
- 03-01-2009, 04:37 AM #3
Member
- Join Date
- Dec 2008
- Posts
- 10
- Rep Power
- 0
Ok, the bes ti can do is translate as exactly as possible the question one the paper( its french), honestly i find it a bit badly written. For reference a Dessing is a Drawing
. Create a class Dessin that represents a drawing on a "plan" , a Dessing is composed of multiple Circles. The circles of the Dessin must be stored in an array.
-
It doesn't say anything it seems about how to get any of the Circles' data. In this situation, I'd punt and just create your circles but use a default constructor.
Without knowing more, I'd avoid getting user input via a console (such as with a Scanner object) inside of the constructor. What if this is for a GUI program where there really isn't supposed to even be a console?
- 03-01-2009, 04:50 AM #5
Member
- Join Date
- Dec 2008
- Posts
- 10
- Rep Power
- 0
The ultimate objective of this project is to display these "Drawings" threw the use of Jframe. Im not quite there yet but i need to get threw the drawing part first,ill email my teacher to try and clarify the question
Any idea what i should ask in this email
-
Hm, I'd ask him just what should be passed to the Drawing class's constructor? The number of circles? Anything about their location or size? Or will we just create an empty array of Circle and fill it with Circle objects as the program is run (perhaps through mouse interaction or through random generation of Circles)?
Good luck
Similar Threads
-
java.net.MalformedURLException: unknown protocol: ntp
By Nicholas Jordan in forum NetworkingReplies: 6Last Post: 12-24-2008, 03:35 AM -
Use MoneyConverter Function to determine change of amount
By javanewbie in forum New To JavaReplies: 0Last Post: 08-21-2008, 01:26 PM -
Calling constructor of parent class from a constructor
By Java Tip in forum Java TipReplies: 0Last Post: 12-19-2007, 09:10 AM -
iteration on huge amount of files in a folder
By tshaked in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 07:08 PM -
Unknown publisher / Signing standalone tomcat.exe
By millross in forum New To JavaReplies: 1Last Post: 06-14-2007, 02:25 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks